How to use g.message outside the controller in Grails?

Possible duplicate:
Grails - receive message value from the controller

I want to use the g.message () method inside the class Service, not Controller. But I can not.

Code example:

// this is a method OUTSIDE a Controller 
def show = {
    def msg = message(code:"foo.bar") // I'm getting error here
}

Is this possible, or do I need to use the old class ResourceBundle?

+3
source share
1 answer

Another question has a great answer:

import org.springframework.context.i18n.LocaleContextHolder as LCH
...
class MyServiceOrMyDomain {
  def messageSource 
  ...
   messageSource.getMessage(key, ["myArg"].toArray(), LCH.getLocale())
  ...
}

Thanks fabien7474

+10
source

All Articles