internationalizationstruts2resourcebundle

Alternative to Struts 2 message resource bundle


I am migrating an application from Struts 1.1 to Struts 2.3. The existing application uses MessageResources from the older framework in the following manner.

<message-resources key="label" parameter="com.abc.xyz.resources.MyLabelResources"/>
<message-resources key="image" parameter="com.abc.xyz.resources.MyImageResources"/>

This way different resources files are separated out and whenever a look-up is done, the bundle key is specified so that it searches in that particular file only.

Based on my understanding on Struts 2.2 framework, I have concluded that I need a global properties file which will do the work for me. However, I would want to create multiple global properties file say for labels and images like the way its working in the existing application (above).

I am not sure how I do this.


Solution

  • If you want to search in particular file only then you can use <s:i18n> tag.

    Using getText method if your action extends ActionSupport

    <s:i18n name="labels">
      <s:property value="getText('some.label')" />
    </s:i18n>
    

    or using <s:text> tag

    <s:i18n name="labels">
      <s:text name="some.label" />
    </s:i18n>
    

    But you can also include more than one properties files to custom default resource bundles:

    <constant name="struts.custom.i18n.resources" value="images, labels" />