Internationalization

Last updated by lucastex 1 year ago

Internationalization

Grails uses Spring and Java I18N mechanisms to supply messages in user-specific languages.

The grails-app/i18n folder contains message bundles (message_xx.properties files) which are Java property files that combine name/value pairs. In that file, variable interpolation is done through the {#} syntax. In particular, {0} is property that failed validation, {1} is class that failed validation, {2} is value that failed validation, and (when appropriate){3} is the data which configured the constraint (e.g. minimum value).

The files must be saved in UTF-8 encoding if you wish to use non-ascii characters, which is contrary to standard Java properties files which use the native Java VM encoding.

Grails automatically converts your UTF-8 properties files to unicode escaped ascii files prior to execution, removing a major pain-point for I18N work.

Within your application you can access the message source from the application context, the bean name is "messageSource", to resolve message codes to text, or within views you can use the <g:message> tag.