Label text based on the locale
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:
custom开发者_如何学JAVAer.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!
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".
精彩评论