I’m trying to translate an app into Japanese and everything was going smoothly until I put it into production.
As cache_classes is now true any translation within a model reverts to the default locale.
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
Many thanks
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.But if you want to translate ActiveRecord field names, use
human_attribute_nameand provide your translations via YML. You do not need to manually provide translations, Rails handles it all for you automatically.The respective documentation is at http://guides.rubyonrails.org/i18n.html Chapter 5.1.