Following this blog article I enabled my application to load i18n messages from the database. It works great. However, I don\'t want to manage all messages in the database
You may extend ReloadableResourceBundleMessageSource (the original grails message bundle, which does not seem to be final) instead and then apply this code:
class DatabaseMessageSource extends ReloadableResourceBundleMessageSource {
protected MessageFormat resolveCode(String code, Locale locale) {
Message msg = Message.findByCodeAndLocale(code, locale)
def format = null
if (msg) {
format = new MessageFormat(msg.text, msg.locale)
}else{
format = super.resolveCode(code,locale)
}
return format;
}
}
You may also reconfigure your message resources in Resources.groovy:
beans = {
messageSource(com.mycompany.DatabaseMessageSource) {
basename = "WEB-INF/grails-app/i18n/messages"
}
}