Has Foreign Language plugin
Plugin details
Documentation
Install the plugin:
ruby script/plugin install git://github.com/factore/has_foreign_language.git
Example
=================
First create your model:
script/generate model books title:string title_fr:string title_de:string author:string
Then specify which fields need to be internationalized in your model:
class Country < ActiveRecord::Base has_foreign_language :title end
Now let’s create a book in the console and see how this works:
I18n.default_locale = "en" b = Book.new(:title => "Slaughterhouse Five", :title_fr => "Abattoir Cinq", :title_de => "Schlachthof Fünf") b.title # Slaughterhouse Five I18n.locale = "fr" b.title # Abattoir Cinq I18n.locale = "de" b.title # Schlachthof Fünf
Calling title on the model returns the appropriate column depending on which locale we’re in. This also works when we change the attribute:
I18n.locale = "de" b.title = "Etwas Anderes" b # Book id: nil, title: "Slaughterhouse Five", title_fr: "Abattoir Cinq", title_de: "Etwas Anderes"
If you want to set or return the default language attribute while in a different locale, you can call it the way you would call any other. Assuming the default is “en”, you would run:
b.title_en # Slaughterhouse Five b.title_en = "Something Else" # Book id: nil, title: "Something Else", title_fr: "Abattoir Cinq", title_de: "Etwas Anderes"
Further Documentation
There is currently no advanced documentation for this plugin.
New documentationEdit plugin | (0 older versions) | Last edited by: hardway, about 1 year ago


