0
Yet another localization library. Maybe with the most agreeable API.
0
+It's simple. Your default language, by default, is English (:en).
0
+Gibberish looks in RAILS_ROOT/lang/*.yml for translation files. Say you have RAILS_ROOT/lang/es.yml,
0
+right? Gibberish will detect that you know about the :es language and will serve up translations
0
+defined in that file if requested to do so.
0
+Here's a real simple example file (it's just "key: translation"):
0
+And, as follows, a real simple example session:
0
+ >> Gibberish.current_language
0
+ >> Gibberish.current_language = :es
0
+ >> Gibberish.current_language = nil
0
+It even works with simple interpolation:
0
+ >> "Hey, {name}!"[:hey_name, 'Chris']
0
+ >> "{name} is from {place}"[:hey_place, 'Chris', 'the Dreamworld']
0
+ => "Chris is from the Dreamworld"
0
+Notice we don't use hashes (#) like normal Ruby interpolation. Also, the names of the variables
0
+in the brackets don't really mean much. Interpolation is done in order -- the first argument replaces
0
+the first variable in brackets, the second the second, etc.
0
+This of course works with your translations:
0
+ hey_name: ¡Hola {name}!
0
+ >> "Hey, {name}!"[:hey_name, 'Chris']
0
+ >> Gibberish.current_language = :es
0
+ >> "Hey, {name}!"[:hey_name, 'Cristóbal']
0
+Neat. What other methods do we get?
0
+The classic around_filter use case:
0
+ >> Gibberish.default_language?
0
+ >> Gibberish.use_language(:es) do
0
+So, in your ApplicationController (or somewhere):
0
+ class ApplicationController < ActionController::Base
0
+ around_filter :use_language
0
+ Gibberish.use_language(session[:language]) { yield }
0
+Finally, some checking methods, if you need them:
0
+ >> Gibberish.default_language?
0
+ >> Gibberish.current_language = :es
0
+ >> Gibberish.default_language?
0
+Languages are loaded by default at Rails startup. In dev mode, language YAML files are reloaded when
0
+modified. No need to reboot the server.
0
+ >> Gibberish.load_languages!
0
+ => [:es, :fr, :de, :kl]
0
+ >> Gibberish.languages
0
+ => [:es, :fr, :de, :kl]
0
=> chris[at]ozmm[dot]org
Comments
No one has commented yet.