joannaSmith12
joannaSmith12

Reputation: 1047

How do I add args to custom i18n messages in grails?

I have an object which I declared as "unique:true" and then I created a custom message in message.properties in grails. It appears correctly, but I don't know how to pass arguments to it. Is it even possible?

net.mypackage.MyObject.myField.unique = The Object {0} already belongs to the Object Group {1}.

I am aware that I can pass args via "g:message" but in this case I am rendering my errors via this snippet:

<g:hasErrors bean="${object}">
                        <ul class="errors no-margin" role="alert">
                            <g:eachError bean="${object}" var="error">
                            <li <g:if test="${error in org.springframework.validation.FieldError}">data-field-id="${error.field}"</g:if>><g:message error="${error}"/></li>
                            </g:eachError>
                        </ul>
                    </g:hasErrors>

I can probably hack it like say do an if-else to determine if the error was a "unique constraint" error then pass the values, but other than that I don't have any idea. Most of the custom message examples I see on the internet are related to custom validators. I tried.. But I dont want to resort to that just yet... Any opinions on how to do this?

Upvotes: 0

Views: 5747

Answers (1)

Tom Metz
Tom Metz

Reputation: 919

From the Grails documentation (http://grails.org/doc/latest/guide/i18n.html):

<g:message code="my.localized.content" args="${ ['Juan', 'lunes'] }" />

Upvotes: 3

Related Questions