views:

397

answers:

1

Hi,

I need to use XML file to store each key/value pair used by my app (instead of the usual properties file).

Grails is using properties file by default to handle internationalization.

What can I do to configure grails to read internationalization information in XML file?

Thanks

+1  A: 

Hello,

Actually, there is a bug in Grails scripts. When packaging, Grails will copy only .properties files located under the folder /grails-app/i18n. Your XML files will be ignored.

To fix it, you can manually edit the file *{grails-sources}/scripts/GrailsPackage.groovy.

Look for:

if(config.grails.enable.native2ascii) {
 profile("converting native message bundles to ascii") {
  ant.native2ascii(src:"${basedir}/grails-app/i18n",
       dest:i18nDir,
       includes:"*.properties",
       encoding:"UTF-8")
 }
}
else {
    ant.copy(todir:i18nDir) {
  fileset(dir:"${basedir}/grails-app/i18n", includes:"*.properties")
 }
}

And replace by:

if(config.grails.enable.native2ascii) {
 profile("converting native message bundles to ascii") {
  ant.native2ascii(src:"${basedir}/grails-app/i18n",
       dest:i18nDir,
       includes:"*.properties, *.xml",
       encoding:"UTF-8")
 }
}
else {
    ant.copy(todir:i18nDir) {
  fileset(dir:"${basedir}/grails-app/i18n", includes:"*.properties, *.xml")
 }
}

It will copy your messages*.xml in the resources path of your Grails app next time you run it. You can use messages.xml as a starting point - it has to respect the Java DTD.

Using in your views will work as it worked with messages.properties files.

rochb
The DTD: http://java.sun.com/dtd/properties.dtd
rochb
Thank you very very much! It's exactly what I was looking for and it works! (very clear explanation thanks!)
Wickramben