views:

712

answers:

3

Hi,

I'd like to create another resource bundle to organize my Grails app. Grails provides a 'messages' resource bundle and I need to create a 'myApp' resource bundle.

How can I create a new resource bundle and read its properties with the 'g:message' GSP tag ?

Thanks a lot.

+4  A: 

You have to create a bean in grails-app/conf/spring/resources.groovy which will override the default MessageSource.

// Place your Spring DSL code here
beans = {
      messageSource(org.springframework.context.support.ReloadableResourceBundleMessageSource) {
        basename = "classpath:grails-app/i18n/myApp"
    }
}

Note: If you need to customize Grails, the only advise I can give you is to get familiar with the Spring framework (and specifically Spring-MVC) with the following links:

rochb
Thanks a lot again for your explanation! I'm able to change the bundle name now but I still have somme problem to define more than one bundle. As the Spring MVC documentation is describing we can pass a list of bundle: <property name="basenames"> <list> <value>format</value> <value>exceptions</value> <value>windows</value> </list> </property>But how to pass a list in the groovy/grails way ? I tried to do basename = ["classpath:grails-app/i18n/myApp","classpath:grails-app/i18n/messages"] but I got an error. Do you have any idea how to pass a list? Thx!
Wickramben
As you wrote it, you can pass a list of bundle with the property name "basenames". So to pass it in resources.groovy, you should use:basenames = ["classpath:grails-app/i18n/myApp", "classpath:grails-app/i18n/messages"].:D
rochb
hoo ok I got it! The 's' that changes everything ;) Thank you so much you rocks!
Wickramben
+2  A: 

Grails (as of version 1.0.3) will add all property files found in the grails-app/i18n directory to the resource bundle automatically. No need to add them manually :)

Cheers

lunohodov
that's true!! I've just realized it.
rochb
A: 

As of Grails 1.3.4, any property files added to the grails-app/i18n directory will be added to the messageSource.

In addition, if you attempt to manually add the bean (and the basenames under it) when you go into the production environment it will not load them. It will work in development mode (tested running off of IDEA 9.0.3 and the tomcat plugin ver.1.3.4), but not in production mode. This happened for me after following the answer provided by rochb (I checked the answer and implemented before trying the simple way), and I had to remove the messageSource bean configuration in order to correct it.

Shawn D