Alexey Poimtsev
Alexey Poimtsev

Reputation: 2847

globalize2 - extract translation for specified locale

Is there any possibility to extract globalize2 translation for specified locale without setting

I18n.locale = :ru 

as i know - i can extract ALL translations using

model.translations

but maybe there are simplest way to extract only for one language?

Upvotes: 0

Views: 351

Answers (2)

Kyle Fox
Kyle Fox

Reputation: 3313

There's actually a pretty simple plugin that will do this for you: http://github.com/tomash/easy_globalize2_accessors

 class Product
    translates :title, :description
    globalize_accessors :pl, :en, :de
  end

will automatically give you accessors like:

product.title_en # => "English title"
product.title_de # => "German title"

Upvotes: 1

Veger
Veger

Reputation: 37915

Suppose that your table is called mytable: Create a Model for the mytable_translations table and use something like

MyTableTranslations.find(:all, :conditions => {:locale => :ru } )

and, like any other query, all records with the ru locate are returned.

Upvotes: 1

Related Questions