Intro

This gem takes an other approach to Javascript internationalization than most others do. I use this in production but you might want to look at it as a proof of concept. The goal is to build a lightweight, unobtrusive and powerful translation solution for Frontend applications by using standard libraries.

Right now, you’ll have to manually provide the following depencencies: Rails, jQuery and Mustache.

Installation

Add the gem to your Gemfile

gem 'internashunalize-js'

Run the generator

rails g internashunalize:js:install

Don’t forget to include the javascript in your Html.

Mark translations you want to use in your scripts

<% t(:yml_key, :javascript => true) %>

Place the view helper somewhere in your layout / views

<%= javascript_translations %>

Usage

Start using the marked translations in your Javascript

I18n.t('yml_key')

For interpolating values, you can pass a Json object as second argument

I18n.t('yml_key_with_variable', { your_variable: 'Variable content' })