Search code examples
struts2internationalizationjstllocale

How to display on the same JSP a resource bundle key several time but in different locales?


Dear Struts 2 and JSP experts,

I can't figure out how to display on the same page a resource bundle key several time but with different locales.

Resource Bundles:

global_fr.properties

#Global messages
global.label = Texte en Français    

global.properties

#Global messages
global.label = Text in English

Expected result:

<table>
  <tr>
    <td>Texte en Français</td>
    <td>${param.label.fr}</td>
  </tr>
  <tr>
    <td>Text in English</td>
    <td>${param.label.en}</td>
  </tr>
</table>

What is the best way to handle this use case with Struts 2 or JSTL ?

Thanks for your help,

Bertrand


Solution

  • You can use S2 <s:i18n> tag for that which allows the <s:text> tag to access messages from any bundle, and not just the bundle associated with the current action.

    <s:i18n name="global_fr">
        <s:text name="global.label"/>
    </s:i18n>
    
    <s:i18n name="global_en">
        <s:text name="global.label"/>
    </s:i18n>