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 mod
Don't use I18n.t or translate method in your models. You can do this instead:
Use something like this to add internationalized errors to the name
attribute of your model (Check documentation: ActiveModel/Errors/method-i-add):
self.errors.add(:name, :your_error_key)
# The error key could be something like :wrong_name
NOTE: Sometimes you won't even need to add errors with errors.add
method. For example if you add validations in your model with somethind like this:
validates :name, presence: true
Rails will add an error with the key :blank
(the key depens on the validation type). In other words rails internally will issue self.errors.add(:name, :blank)
Then in your locale.jp.yml can use any of this (just one):
activerecord.errors.models.[model_name].attributes.[attribute_name]
activerecord.errors.models.[model_name]
activerecord.errors.messages
errors.attributes.[attribute_name]
errors.messages
In your case replace [model_name]
with timeseries_forecast
and [attribute_name]
with your_error_key
For example:
en:
errors:
messages:
your_error_key: "Your error message in english"