问题
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?
回答1:
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:
- Customize Message source within Spring
- Configure beans within Grails
回答2:
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 :)
回答3:
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 v1.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.
来源:https://stackoverflow.com/questions/1522568/create-a-new-resource-bundle-in-grails