How to use globalize
In your models
class Product < ActiveRecord::Base
translates :name, :description, :specs
end
Create a row and its translation:
Locale.set_base_language('en-US')
Locale.set('en-US')
Product.create!(:name => 'Meatballs')
Locale.set('es-ES')
prod = Product.find(1)
prod.name = 'Albóndigas'
prod.save
Then:
Locale.set("en-US")
prod = Product.find(1)
prod.name -> "Meatballs"
Locale.set("es-ES")
prod = Product.find(1)
prod.name -> "Albóndigas"
In your views (or anywhere else)
Locale.set("he-IL")
<%= "Thanks for ordering!".t %> -> "תודה על ההזמנה!"
<%= "You've got %d items in your cart" / 5 %> -> "יש 5 מוצרים בסל שלך"
Locale.set("es-ES")
<%= Time.now.localize("%d %B %Y") %> -> "17 Octubre 2005"
<%= 12345.45.localize %> -> "12.345,45"
There’s more, see Features.
revision 1 · 25.06.08 00:41 · by: Sven