Possible Duplicate:
Grails - getting a message value from 开发者_JS百科controller
I want to use a g.message() method inside a Service
class, not a Controller
.
But I can't.
Code example:
// this is a method OUTSIDE a Controller
def show = {
def msg = message(code:"foo.bar") // I'm getting error here
}
It's possible to do this, or I have to use the old ResourceBundle
class?
Another question have a perfect answer:
import org.springframework.context.i18n.LocaleContextHolder as LCH
...
class MyServiceOrMyDomain {
def messageSource
...
messageSource.getMessage(key, ["myArg"].toArray(), LCH.getLocale())
...
}
Thanks to fabien7474
精彩评论