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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With