我正在尝试将应用翻译成日语,直到我将其投入生产之前,一切都进行得很顺利.
I'm trying to translate an app into Japanese and everything was going smoothly until I put it into production.
由于cache_classes现在为true,因此模型中的任何转换都将恢复为默认语言环境.
As cache_classes is now true any translation within a model reverts to the default locale.
我知道我应该直接在yml文件中定位翻译,但是我不确定如何对以下简化代码进行翻译:
I know I'm probably supposed to target the translations directly in the yml file but I'm not sure how I would do that for the following simplified code:
class TimeseriesForecast < ActiveRecord::Base @@field_names = { :location_name => I18n.t('forecast_timeseries.location_name'), :local_date_time => I18n.t('forecast_timeseries.local_date_time'), :zulu_date_time => I18n.t('forecast_timeseries.zulu_date_time'), :temp_mean => I18n.t('forecast_timeseries.temp_mean') } end非常感谢
推荐答案您的I18n.t()调用是在编译时评估的,因为您正在定义类变量,而不是实例变量.您需要致电I18n.t,以便在运行时对其进行评估.
Your I18n.t() call is evaluated at compile time since you are defining class variables, not instance variables. You need to put your call to I18n.t where they will be evaluated at runtime.
但是,如果要翻译ActiveRecord字段名称,请使用human_attribute_name并通过YML提供翻译.您无需手动提供翻译,Rails会自动为您处理所有翻译.
But if you want to translate ActiveRecord field names, use human_attribute_name and provide your translations via YML. You do not need to manually provide translations, Rails handles it all for you automatically.
相关文档位于 guides.rubyonrails/i18n.html 第5.1章.
The respective documentation is at guides.rubyonrails/i18n.html Chapter 5.1.
更多推荐
在生产中的模型中进行Rails 3翻译
发布评论