The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Multilingual Rails Tutorial

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Warren Brian Noronha

Posts: 58
Nickname: wnorrix
Registered: Feb, 2005

Warren Brian Noronha is hardcore Ruby/RoR and FLOSS supporter. Currently working for Norrix.
Multilingual Rails Tutorial Posted: Sep 11, 2005 3:30 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Warren Brian Noronha.
Original Post: Multilingual Rails Tutorial
Feed Title: HyperionReactor - Ruby, Ruby On Rails
Feed URL: http://viper.unixbsd.info/suspended.page/
Feed Description: My blogs on Ruby and Ruby on Rails.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Warren Brian Noronha
Latest Posts From HyperionReactor - Ruby, Ruby On Rails

Advertisement

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.

  1. 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:

Read: Multilingual Rails Tutorial

Topic: DHH: Reduce the risk, hire from open source Previous Topic   Next Topic Topic: Interviewed for newz.dk podcast [DK]

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use