It seems that the translation does not work in production mode: in all
languages it’s always the english translation that gets diplayed
(probably because I set english as the default locale in my app…?).
So I am assuming that we can’t translate validations in models, because
models get loaded only once - when the server is booted (and then, the
default locale would be applied).
Am I right? If yes, how would you solve this problem?
So I am assuming that we can’t translate validations in models, because
models get loaded only once - when the server is booted (and then, the
default locale would be applied).
Am I right? If yes, how would you solve this problem?
On Wed, Dec 15, 2010 at 11:16 AM, Marnen Laibow-Koser [email protected]wrote:
Best,
since that is the default behavior i assumed ‘please_select_whatever’
is a
dynamic value taken from the model, if its not the case
everything should word without the need of doing the translation in the
model
Thanks for the suggestion - unfortunately, it doesn’t change the
outcome…
Perhaps you should just have the validation routine generate the
translation key (in other words, leave off I18n.t), then apply the
translation in the view layer.
So I am assuming that we can’t translate validations in models, because
models get loaded only once - when the server is booted (and then, the
default locale would be applied).
Am I right? If yes, how would you solve this problem?
In particular see the table in section “5.1.2 Error Message
Interpolation”
Nope, this doesn’t work. I suspect it’s still the same problem: it seems
not possible to have translations in models (since they only get loaded
once).
It may work for the default “keys” (for “validates_presence_of :name”
the key would be “blank”), but not the custom ones.
In order to get locales working at runtime, I made the ActiveRecord
validations call a proc (IIRC, similar to how Rails 3 does it now).
If you’re using a Rails gem, or Rails is vendored, and you don’t want
it to be lost when upgrading, put it in an all_extensions.rb
initializer, like I did here: