简体   繁体   English

更改网络应用程序语言

[英]Change a web application language

I have a web application built in a single language and I would like to internationalize it by adding a few more languages. 我有一个用单一语言构建的Web应用程序,我想通过添加更多语言来使其国际化。 I would like to do it using a properties file containing keys and values (keys like 'name' and the value of this key changes in each properties file) . 我想使用包含键和值(每个属性文件中的键,例如'name'和此键的值更改)的属性文件来执行此操作。 I read some time ago that there were an application that was capable of extract the labels from the jsp files and generate the properties file which the keys. 我前一段时间读到,有一个应用程序能够从jsp文件中提取标签并生成键的属性文件。 Can someone tell me what would the best way to do this? 谁能告诉我最好的方法是什么?

Thank you. 谢谢。

Try using ResourceBundle. 尝试使用ResourceBundle。 Say you have your localized property files called Resources_EN.properties, Resources_FR.properties, etc. You have to put your property files in the classpath. 假设您具有名为Resources_EN.properties,Resources_FR.properties等的本地化属性文件。您必须将属性文件放入类路径中。 To get a localized string you do the following: 要获取本地化的字符串,请执行以下操作:

ResourceBundle resourceBundle = ResourceBundle.getBundle("Resources", new Locale("EN");
String value = resourceBundle.getString("myKey");

Is that web application used Struts? 该Web应用程序使用了Struts吗? If yes. 如是。 It very easy to change the code. 更改代码非常容易。 You have to change the Web.xml for I18N and jsps to get the property file according to language. 您必须更改I18N和jsps的Web.xml才能根据语言获取属性文件。

step 1 : use properties file for every language you want
step 2 : in all your view pages dont give static values but pick from language properties file

you can also refer this link as per your comfort 您也可以根据自己的喜好引用此链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM