I found a way to dynamically switch languages in your rails


#1

step 1) Do what is there in the manual Using Gettext To Translate Your
Rails
Application as it is.

Step2)Now create a table in your project database to store your language
names which you are supporting in the project for example “langs”

step 3)populate your table with language names, namely hindi, japanes
etc.

step 4) create a scffold for with aLang controller, just so that life is
easy.

step 5)now in your layout directory edit the .rhtml , place a
code
to select the language
<%= start_form_tag :action => ‘lang_switch’ %>
<%= select (“post”,“lang_id”,Lang.find_all.collect{|p| [p.language]})%>
<%= submit_tag “Go” %>
<%= end_form_tag %>

step 6)now in your application.rb file create a method like this
def lang_switch
if @params[“post”][“lang_id”] == “my_fav_lang” #compare the
parameters
sent by browser
cookies[:lang] = { :value =>
“my_fav_lang_dirname_in_po_directory”}

set the language cookie ,mostly this is like en or gb or jp etc

    flash[:notice] = 'my_fav_lang language selected.'
    redirect_to :action => 'list' #redirect the page
end
else if @params["post"]["lang_id"] == "my_fav_lang2"
    cookies[:lang] = { :value => 

“my_fav_lang_dirname_in_po_directory2”}

    flash[:notice] = 'my_fav_lang2 language selected.'
     redirect_to :action => 'list'
 end

end

Step 7) thats it that does it. you select your language and click go ,
you
get a reloaded page with your favorite language.

NOTE: IT WORKED FOR ME FOR A SMALL APP LIKE A TODO APP. AND I HOPE IT
CAN BE
APPLIED TO APP OF ANY COMPLEXITY.