Possible Duplicate:
Grails - getting a message value from controller
我想使用g.message() Service
内的方法类,而不是 Controller
。
但我不能。
代码示例:
// this is a method OUTSIDE a Controller
def show = {
def msg = message(code:"foo.bar") // I'm getting error here
}
可以这样做,否则我必须使用旧的 ResourceBundle
类?
最佳答案
另一个问题有完美答案:
import org.springframework.context.i18n.LocaleContextHolder as LCH
...
class MyServiceOrMyDomain {
def messageSource
...
messageSource.getMessage(key, ["myArg"].toArray(), LCH.getLocale())
...
}
关于grails - 如何在 Grails 的 Controller 之外使用 g.message?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5903689/