Browse the Ruby on Rails Community.

You are here: Browse Railsplugins For 1.2

For 1.2

=Welcome to Globalize

Globalize is a Ruby on Rails plugin designed to support globalized applications. It supports translation into multiple languages (for both db content and controller and view code) and localization of time, data, and numbers. It’s under the MIT License, same as Ruby on Rails.

How to use it

Decide where you’d like globalize to store your translations.

By default globalize stores translations externally in a dedicated table but now you also have the option to store translations within the model’s own table.

To set this method as the default for add:

Globalize::DbTranslate.keep_translations_in_model = true

to your environment.rb.

= In your models #All translations stored in a separate table class Product < ActiveRecord::Base translates :name, :description, :specs end

or you can override the global setting per model by:

All translations stored ‘products’ table

class Product < ActiveRecord::Base

self.keep_translations_in_model = true

translates :name, :description, :specs

end

Then:

Using keep_translations_in_model = false:

Locale.set("en-US")
prod = Product.find(1)

prod.name -> “Meatballs”

Locale.set("es-ES")
prod = Product.find(1) #Note: A reload of the model instance is required after a locale change.

prod.name -> “Albondigas”

Using keep_translations_in_model = true:

Locale.set("en-US")
prod = Product.find(1)

prod.name -> “Meatballs”

Locale.set("es-ES")

prod.name -> “Albondigas” #Note: No reload of model is required

=== In your views (or anywhere else)

Locale.set("he-IL")
&lt;%= "Thanks for ordering!".t %> -> "תודה על ההזמנה!" 
&lt;%= "You've got %d items in your cart" / 5 %> -> "יש 5 מוצרים בסל שלך"
Locale.set("es-ES")
&lt;%= Time.now.loc("%d %B %Y") %> -> "17 Octubre 2005" 
&lt;%= 12345.45.loc %> -> "12.345,45"

See the wiki (http://www.globalize-rails.org/) for more documentation.

== How to install

From your rails app root directory:

1. script/plugin install http://svn.globalize-rails.org/svn/globalize/branches/for-1.2 2. rake globalize:setup (might take a while, about a minute or so)

...and you’re globalized, dude!

Optionally, try:

  • rake test_plugins
  • rake plugindoc

NOTE: This description has been extracted from the Plugin README and so the formatting may need updating to make browser friendly

Users


See all 5 member details


Membership

+ Join this railsplugin

Record Maintainer

'None'