Monday, December 20, 2010

Set a fixed Locale in Grails

Grails has a nice feature that resolves the application's locale based on factors like request-header information, the request-parameter 'lang=xx' and the default locale of the VM.
But some projects don't need such flexibility. Rather they want to make sure that a specific locale is used always.

All you need to do is adding Spring's FixedLocaleResolver and set the VM's default locale. Add the following code to your resources.groovy:

localeResolver (FixedLocaleResolver, Locale.GERMANY) {
   Locale.setDefault (Locale.GERMANY)