简体   繁体   English

globalize2-提取指定语言环境的翻译

[英]globalize2 - extract translation for specified locale

Is there any possibility to extract globalize2 translation for specified locale without setting 是否有可能在没有设置的情况下提取指定语言环境的globalize2翻译

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? 但是也许有最简单的方法只提取一种语言?

Suppose that your table is called mytable : Create a Model for the mytable_translations table and use something like 假设您的表名为mytable :为mytable_translations表创建一个模型,并使用类似

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

and, like any other query, all records with the ru locate are returned. 与其他查询一样,返回所有带有rulocate的记录。

There's actually a pretty simple plugin that will do this for you: http://github.com/tomash/easy_globalize2_accessors 实际上,有一个非常简单的插件可以为您完成此操作: 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM