Let’s suppose that we have a <my project>/i18n/parameters.properties file which has line
myparameter.something=My ValueSo, if we want to get the ‘My Value’ value on a *.gpg page we just need write:
${message(code: 'myparameter.something', default: 'Some default 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: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())
}
}
That's all folks!
No comments:
Post a Comment