Skip to content

giniedp/j18n

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

j18n

This plugin enables your rails i18n strings in your javascript.

Requirements

Rails3

Installation

In your Gemfile

gem 'j18n', :git => 'git://github.com/giniedp/j18n.git'

Then run

bundle install

and

rails generate j18n:install

This will generate (overwrite) an initializer at

config/initializers/j18n.rb

Modify that file with your settings

J18n.setup do |config|
  # Set the javascript output file path
  config.output_path = "public/javascripts/j18n.js"
  
  # If true, the javascript file will be generated on application startup
  config.build_on_boot = false
end

Include the javascript in your application layout or wherever you need the i18n

= javascript_include_tag 'j18n'

You can also use a generator to build the i18n file

rails generate j18n:regenerate

Usage

After you run the generator you can use the translate method in your javascript as you are used from rails

I18n.t("path.to.locale");

This will lookup a value at "en.path.to.locale". "en" is the default locale. If you want to change it, use

I18n.locale = "de";

Copyright

Copyright (c) 2010 Alexander Gräfenstein. See LICENSE for details.