Some of you have already integrated my patch, some of you have already figured out how to use it without any help ( that was the initial plan after all ). As for those who don't, here goes.
_I did promise earlier that the support will be modular just like our views, but since the system loads all the languages into memory before serving request, I decided to drop it for now._
*Step 1. Locale directory*
All the language files are supposed to be stored here.
# mkdir app/locale/
*Step 2. Create the lyml file*
This is where you store all your language strings, it is recommended you use the iso standard eg. en-gb.lyml, en-us.lyml etc...
*Step 3. Add strings*
You now need to add all the strings you are going to use in your application, since this is yaml you dont need to be a genius to add stuff, and remember to use a editor that supports utf like emacs or vi.
file: en-gb.lyml
en-gb:
hello: Hello-gb
world: World-gb
file: en-us.lyml
en-us:
hello: Hello-us
world: World-us
*Step 4. Setting the default language*
The system stores the language to use in session[:language]. You now need to add some code to set a language if it has not been set, I am working on a way where you can specify your default language in environment.rb
*Step 5. Usage*
Now in your views you can simply just do a <%= t 'hello' %><%= t 'world' %> and depending on the language you have set, it will use the correct strings. You can also do a <%= t 'hello', 'en-gb' %> where it will output the hello string for en-gb even if the language environment is set to en-us
Technorati Tags: Ruby on Rails