Search code examples
ruby-on-railsglobalize2

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?


Solution

  • 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"