16.3 Reading Messages - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.9
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" />
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.
<g:message code="my.localized.content" args="${ ['Juan', 'lunes'] }" />
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'])
}
g.
:def myTag = { attrs, body ->
def msg = g.message(code: "my.localized.content", args: ['Juan', 'lunes'])
}