Loading...

Tuesday, March 29, 2011

Grails Goodness: Splitting i18n Message Bundles

Grails supports internationalization out of the box. In the directory grails-app/i18n we find a messages.properties with default Grails messages. We only have to make a new properties file where the name ends with the locale to add messages for another locale to our application.

But we are not restricted to the basename messages for our message bundles. We can use any name as long as we place the file in the grails-app/i18n directory. For example we can create a file views.properties to store messages related to the Groovy Server Pages and a file validation.properties with messages related to validation of domain objects. And if we want specific messages for the Dutch locale for example we create views_nl.properites and validation_nl.properties.

4 comments:

Manoj said...

Hi ,
A newbie to grails ..i tried putting a file named messages_es_widget.properties into the i18n folder that already had the messages_es.properties file. Both of them had separate content.
Although it showed the file in resource bundle in IntelliJ IDEA ... it did not render them in the final output on the page.
When I deleted the older one(messages_es.properties) and renamed the new one(messages_es_widget.properties) to messages_properties .. it worked ..

Somehow i feel that the system is picking up only 1 file for 'es'. Could you throw any light on this situation ??

Any help would be greatly appreciated ..

Thanks
Grails-Newbie

mrhaki said...

@Manjo: you should rename the file to messages_widget_es.properties. So the locale is defined after the basename.

Manoj said...

thanks for the quick reply ...
i tired that . .. still didn't work ... I check it by simply putting a ?lang=es
Currently i have 2 files messages_widget_es.properties and messages_es.properties.
Earlier it was atleast shown inside the Resource Bundle .. now it isn't ..
I had event tried widget_messages_es.properties .. but to no avail .. :(


Regards Manoj

mrhaki said...

@Manoj: the basename shouldn't contain an underscore. So if the file is renamed to messages-widget_es.properties it works.

Post a Comment