I use message.properties
for i18n. I have the the following property files.
message.properties
message_de.properties
This works fine when I do something like this:
Locale locale = new Locale("de")
def test = g.message(code:'some.code', locale: locale)
The problem is when I use a Locale
like this:
Locale locale = new Locale("de_DE")
In the former case Grails searches for a property file message_de_DE.properties
which does not exist so it falls back to message.properties
.
How can I force Grails to do the following?
properties
file which matches the requested Language code and Country code of the Locale.properties
file which matches the requested Language codemessage.properties
.Just changing
Locale locale = new Locale("de_DE")
to
Locale locale = new Locale("de", "DE")
should achieve what you want.
AFAIK Grails by default does what you mentioned in your points, there is no need to force.
The single argument constructor of Locale
expects the argument to be a language name, but de_DE is not a valid language name (This may be the reason grails falls back to message.properties
). You have to use the other variant of the constructors which take language name as the first argument and country name as the second. The doc.