Search code examples
grailsradio-buttongsp

How to use i18n with a Grails radioGroup?


How does the message needs to be set in messages.properties to get the label translated? (I'm on Grails 2.4.4)

Domain:

int handledBy    

messages.properties:

Case.handledBy.1=Handled by A
Case.handledBy.2=Handled by B```   

View:

<g:radioGroup name="handledBy" values="[1,2]">
    <tr class="prop">
        <td valign="top" class="name">
           <label><g:message code="${it.label}" />:</label>
        </td>
        <td valign="top" class="value ${hasErrors(bean:CaseInstance,field:'handledBy','errors')}">                               
            ${it.radio}
        </td>
   </tr>
</g:radioGroup>    

Solution

  • You can use labels attribute of the g:radioGroup tag for this, like

    <g:radioGroup name="handledBy" values="[1, 2]" labels="['Case.handledBy.1', 'Case.handledBy.2']">
        ...
        <label><g:message code="${it.label}"/>:</label>
        ...
    </g:radioGroup>
    

    and add messages in messages.properties

    Case.handledBy.1=Handled by A
    Case.handledBy.2=Handled by B