I’ve been following the Rails development team since they started working on a built-in 118N solution. We’ve just delivered an application that has to support both english and arabic; so, the project was a perfect fit for the new I18N functionality because I needed support for view and model translations.

I’ve decided to write a simple plugin to simplify the code contained in my views, it’s called translated_attributes, and you can grab it now.
In the example above, I created a model call Post, that contains the same content in two languages; for example the title attribute is title_en for english, and title_ar for arabic. In the application, the locale is defined by the path and is always set on a before_filter; this allows me to use call the title attribute, that will return the appropriate attribute making my view code simpler.
Of course, this solution fits well my scenario that specifies that some content is always to be translated in two languages; so, your requirements if this plugin suits you or not. If you need to translate text in more than 2 languages, I wouldn’t recommend the one-field-per-language approach.
Post a Comment