Let’s suppose that we have a <my project>/i18n/parameters.properties file which has line
So, if we want to get the ‘My Value’ value on a *.gpg page we just need write:
- myparameter.something=My Value
But, what to do if it’s necessary reading a property’s value in a Groove Class? The answer is quite easy! Supposing the same parameters.properties file we supposed before, we can do:
- ${message(code: 'myparameter.something', default: 'Some default value')}
That's all folks!
- import org.springframework.context.i18n.LocaleContextHolder as LCH
- class MyClass {
- /** Dependency injection for getMessage. */
- def messageSource
- public def getMyParameter(){
- return messageSource.getMessage('myparameter.something', null, 'Some default value', LCH.getLocale())
- }
- }
No comments:
Post a Comment