editor field validation with multiple languages
editor field validation with multiple languages
How can I use multiple language error messages without having to provide English wording for the default validation again?
As I see it right now I must specify a "message" entry in the array passed to validator if I want another language. I have no option to leave it empty and have validator provide the English default messages. I can only drop the "message" entry completely to get the English default error messages, but then I cannot have a translation at all. This makes a mess with the code I guess because I need different "Field::inst ... " statements per language. Do you have an idea how to solve this more elegantly?
This question has an accepted answers - jump to answer
Answers
That would be a nightmare for certain!
The why I approach this myself is to have the language name stored in a session variable (although it could be stored anywhere) and have a lookup function that will provide the translation - e.g.:
Then the
i18n()
method would either look up a translation for that string, or if the language is English, just use that default:I tend to actually use a JSON token rather than the English phrasing, but I've seen both ways being used in various applications. I guess if you wanted the translations to all be inline, you could simply define them in an array that is passed to the
i18n()
function that would then pick the correct one.Allan
Thanks, Allan!