0.0
No commit activity in last 3 years
No release in over 3 years
A simple rails engine for client-side translation
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 3.2
 Project Readme

#i18n-coffee

Client Side Localisation for Rails

Gem Version

##Usage

In your Gemfile add

gem 'i18n-coffee', '~> 0.1.3'

##Setup locale translations

By default, it looks for javascripts node in your {locale}.yml.

# config/locales/en.yml
en:
  javascripts:
    hello: "Hello"

##On the client-side

In your app/asssets/javascripts/application.js file include i18n

//= require i18n

You can now try use window.translate or window.t for translation lookup.

window.t('javascripts.hello'); // "Hello"

Based on I18n.locale in Rails, it will load the corresponding translations from your locale files.

###Passing variables to translation

You can use variables to generate dynamic content in the client-side translations the same way that Rails does.

window.t('javascripts.greeting', { name: "Mann" });
# config/locales/en.yml
en:
  javascripts:
    greeting: "Hello %{name}!"

##Change javascript translations root

You can choose a different root node as the translations.

# config/locales/en.yml
en:
  views:
    home:
      title: "Hello world!"

To select views.home as translation root:

# config/application.rb
config.i18n_translations_root = 'views.home'

The translation root setting = views.home in config/application.rb will become views_home in client-side lookup key.

window.t('views_home.title'); // "Hello world!"