16.3 Reading Messages 3.1.7

See the light - agile, industrial strength, rapid web application development made easy

(Quick Reference) # 16.3 Reading Messages - Reference Documentation Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari Version: 3.1.7 ## 16.3 Reading Messages #### Reading Messages in the View The most common place that you need messages is inside the view. Use the message tag for this:
    <g:message code="my.localized.content" />
As long as you have a key in your `messages.properties` (with appropriate locale suffix) such as the one below then Grails will look up the message:
    my.localized.content=Hola, Me llamo John. Hoy es domingo.
Messages can also include arguments, for example:
    <g:message code="my.localized.content" args="${ ['Juan', 'lunes'] }" />
The message declaration specifies positional parameters which are dynamically specified:
    my.localized.content=Hola, Me llamo {0}. Hoy es {1}.
#### Reading Messages in Controllers and Tag Libraries It's simple to read messages in a controller since you can invoke tags as methods:
    def show() {
        def msg = message(code: "my.localized.content", args: ['Juan', 'lunes'])
    }
The same technique can be used in tag libraries, but if your tag library uses a custom namespace then you must prefix the call with `g.`:
    def myTag = { attrs, body ->
        def msg = g.message(code: "my.localized.content", args: ['Juan', 'lunes'])
    }
| Quick Reference (hide)