grails - 如何在 Grails 的 Controller 之外使用 g.message?

标签 grails internationalization tags controller

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())
  ...
}

感谢fabien7474

关于grails - 如何在 Grails 的 Controller 之外使用 g.message?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5903689/

相关文章:

jquery - 将参数传递给 shown.bs.modal function()

mysql - Grails 2.4.3 & MySQL & grails.project.fork = false

java - Grails 项目无法解析 org.junit

GWT i18n 和图像

php - 使用翻译行为时如何查询翻译的内容?

grails - 我如何在 Spring Security Grails 上自定义/登录/验证?

scala - 如何让用户在 play framework 2 中切换语言

javascript - 在 javascript 中更改没有 id 的文本 b/n Span 标记

mysql - sql获取链接表中的标签

ios - 更改UIButton背景时,无法识别的选择器发送到实例