Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good way to introduce constant string to i18n internationalization file in grails

In grails, is there a way in the i18n file to reference a constant value. I'm trying to do something like this:

constant.sitename=Fancy SiteName

intro.headline.label=Welcome to {constant.sitename}
home.headline=You're at {constant.sitename}

The reason is I don't want to change the sitename in every single string if we decide to change the name, I only want to do it once. Is there a way to accomplish this requirement?

I realize I could also set a constant in the Config.groovy, but then that would require passing in the param on every single message that required it, which I'd rather not have to do this as it would make developers lives worse.

like image 343
Scott Avatar asked Nov 05 '22 14:11

Scott


1 Answers

You might override Grails' standard messageSource bean by a custom implementation in resources.groovy. By default the Grails i18n plugin uses PluginAwareResourceBundleMessageSource for this.

So, subclass this and override the necessary code to add property replacement. Don't know by heart what exact methods these are, but that should be easy to figure out with a debugger.

like image 106
Stefan Armbruster Avatar answered Nov 15 '22 06:11

Stefan Armbruster