How to change a normal struts2 project to support multi-language
2010-10-19 17:51
281 查看
You can do it step by step as follow.
Step 1, Detect if the encoding of the project is UTF-8. If not, change its encoding to UTF-8.
Step 2, Add configuration in struts' config file[src/struts.xml].
<constant name="struts.custom.i18n.resources" value="messageResource" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.locale" value="en_US"> </constant>
Step 3, Add propertites files to src. the file name's format is messageResource_lang_county.properties. Take chinese and english for example:
messageResource_zh_CN.properties, messageResource_en_US.properties...
The content's format in property file is key/value, and one pair per line:
Login.Login=Login
Login.Language=Language
HelloWord={0},Hello World
...
Step 4, Replace labels you want to change in jsp page with the struts tag as follow methods.
1, <s:property value="%{getText('Login.Login')}"/>
2, <s:text name="Login.Language"/>
3, <s:text name="HelloWord">
<s:param>Mike</s:param>
</s:text>
Step 4, Replace strings you want to change in action as follow methods.
1, getText("Login.Language")
2, getText("HelloWord", {"Mike"})
At this time, The page's language will be same as your browser's language. And if you want to change the language manually, you should do the next step.
Step 5, Add a action to change the current Locale.
request.getSession().setAttribute("WW_TRANS_I18N_LOCALE", currentlocale);
Wish it can help you.
Step 1, Detect if the encoding of the project is UTF-8. If not, change its encoding to UTF-8.
Step 2, Add configuration in struts' config file[src/struts.xml].
<constant name="struts.custom.i18n.resources" value="messageResource" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.locale" value="en_US"> </constant>
Step 3, Add propertites files to src. the file name's format is messageResource_lang_county.properties. Take chinese and english for example:
messageResource_zh_CN.properties, messageResource_en_US.properties...
The content's format in property file is key/value, and one pair per line:
Login.Login=Login
Login.Language=Language
HelloWord={0},Hello World
...
Step 4, Replace labels you want to change in jsp page with the struts tag as follow methods.
1, <s:property value="%{getText('Login.Login')}"/>
2, <s:text name="Login.Language"/>
3, <s:text name="HelloWord">
<s:param>Mike</s:param>
</s:text>
Step 4, Replace strings you want to change in action as follow methods.
1, getText("Login.Language")
2, getText("HelloWord", {"Mike"})
At this time, The page's language will be same as your browser's language. And if you want to change the language manually, you should do the next step.
Step 5, Add a action to change the current Locale.
request.getSession().setAttribute("WW_TRANS_I18N_LOCALE", currentlocale);
Wish it can help you.
相关文章推荐
- Error:Failed to resolve: com.android.support或者Install Repository and sync project问题
- Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompa
- Jack is required to support java 8 language features. Either enable Jack o的解决
- How To Convert Maven Based Java Project To Support Eclipse IDE
- Error:Jack is required to support java 8 language features.
- Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompa
- Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompa
- [How To]Let EditPlus Support LUA Language (Windows)
- C++ debug "cannot find the file Debug\***.pch" & how to debug multi-projects under one solution
- from program multi language support
- 【记录】AutoMapper Project To not support ResolveUsing
- Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompa
- how to deal with the situation that the language support option disappears in linux ubuntu
- Error:Jack is required to support java 8 language features. Either enable Jack or remove sourceCompa
- .NET Multilanguage Project
- Adding an Unsupported Language to a Project
- This version of Visual Studio .NET does not support source controlled projects. Any changes that you make to this project will n
- How To Add MFC Support to an ATL Project
- android studio项目报:Error:Jack is required to support java 8 language features. Either enable Jack
- Multi-Language of web application project