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

Comments
Where to get the patch itself?
Could you point a Rails newbie to where can I actually download the patch file? I tried looking at pending patches at dev.rubyonrails.com but to no avail.
The Patch
I still have to clean up the patch, I was working on my homepage and a couple presentations this weekend. I will be releasing the patch on this site, when its ready. Hopefully if all goes well, by monday it should be out for review.
- Warren
Gettext
Why not just use gettext ?
Does your solution provide anything that gettext doesn't or is it simply that you do not want to rely on a solution external to Ruby / Rails ?
One advantage that gettext has is that you can add new strings to your application and gettext will merge them in to your language files automatically. Do you intend to incorporate similar functionality?
Post new comment