Globalize2 仅从模型中获取翻译后的属性
class Site < ActiveRecord::Base
translates :title, :content
attr_accessor :rank
end
如何仅列出与 Translates 方法一起使用的 Site 模型的属性? (在这种情况下,我应该得到一个带有 ['title', 'content'] 的数组,没有排名属性,因为它没有被翻译。
class Site < ActiveRecord::Base
translates :title, :content
attr_accessor :rank
end
How I can list only the attributes of the Site model, which work with the translates method ? (in this case, I should get an array with ['title', 'content'], without the rank attribute, because it is not translated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
翻译存储在一个单独的表中,可以通过关联
globalize_translations
访问。因此,要获取这些内容,只需执行 a
然后您必须过滤掉未翻译的列,例如
id、site_id、 locale、created_at、updated_at
其余的应该是您已翻译的。如果您想要获取正在翻译的属性而不是其内容,那么您可以在 globalize_options 中找到它们:
Site.globalize_options[:translated_attributes]
The translations are stored in a separate table, accessible through the association
globalize_translations
So, to get those, just do a
Then you will have to filter out the non-translated columns like
id, site_id, locale, created_at, updated_at
the remaining ones should be the ones that you have translated.If what you want is to get which attributes that are being translated and not the contents of it, then you can find them in the globalize_options:
Site.globalize_options[:translated_attributes]