根据区域设置标记文本

[英]Label text based on the locale


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

我想根据Locale显示标签名称(如英语或法语)。

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"/>"));

我在Java类中有一个数组列表。在此列表中,我想根据区域设置存储值:arraylist.add(new ListItem(“CustomerName”,“ ”));

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

当我在jsp上检索这样的值时:

I have not implement this yet.

我还没有实现这个。

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

我正朝着正确的方向前进吗?有什么建议?谢谢!

1 个解决方案

#1


0  

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.

是的,这是一种标准方法,但该功能已经内置到您可以使用的几乎所有Web框架中,也已经内置到Struts中。这是Struts 2文档中Localization部分的链接。

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:

编辑:再次查看你的问题,这次实际上是在读它...列表是什么?不,那不行。简单地把它放在你的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".

根据用户的区域设置呈现正确的标签,无需额外的工作。具有法语定位的用户将看到“Nom”,其他人都是“姓名”。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2010/10/11/d221e8a49ea1e3d9a98544de33526b63.html



 
  © 2014-2022 ITdaan.com 联系我们: