views:

34

answers:

1

I want to display the label name depending on the Locale (like English or French).

I have two properties file:

messages.properties:
customer.name=Name

messages_fr.properties:
customer.name=Nom

I have an array list in a Java class. In this list I want to store the values depending on the locale:
arraylist.add(new ListItem("CustomerName", "<s:text name="customer.name"/>"));

When I retrieve the value on jsp like this:
<s:param name="prefix" value="'CustomerName'" />

I have not implement this yet.

Am I going the right direction? Any suggestions? Thanks!

A: 

Yes, that's a standard approach, but that functionality is already built into pretty much every web framework you could use, and also into Struts. Here's a link to the Localization section from the Struts 2 docs.

Edit: Looking at your question again, this time actually reading it... what is the list for? No, that won't work. Simply put this in your JSP:

<s:text name="customer.name"/>

That renders the proper label depending on the locale of the user, no extra work required. Users with a French locate will see "Nom", everyone else "Name".

Henning
i have simply used <s:text name="customer.name" /> on display.jsp. but it does not take the effect. should i use array list task as described above to store the customer name so that i can find key value (customer name) on display.jsp ..?
singh
please check this question: http://stackoverflow.com/questions/3912029/activity-display-dynamically-depend-on-the-locale-on-struts-2
singh