1, Test.java
Package com.i18n; Import Java.util.Locale; Public class Test1 { publicstaticvoid main (string[] args) { = locale.getavailablelocales (); for (Locale locale:locales) { locale.getcountry ()); }}}
2, Test2.java
Package com.i18n; import java.util.*; Public class Test2 { publicstaticvoid main (string[] args) { // get local locale Locale locale = locale.getdefault (); = Resourcebundle.getbundle ("Hellofile", locale); = bundle.getstring ("Hello"); System.out.println (value);} }
3, Test3.java
Packagecom.i18n;ImportJava.text.MessageFormat;ImportJava.util.Locale;ImportJava.util.ResourceBundle; Public classTest3 { Public Static voidMain (string[] args) {locale locale=Locale.getdefault (); ResourceBundle Bundle= Resourcebundle.getbundle ("Hellofile", Locale); String value= bundle.getstring ("Hello"); String result= Messageformat.format (Value,Newobject[]{"Beijing"}); SYSTEM.OUT.PRINTLN (result); }}
4. Define Properties File
Hellofile_en_us.properties
Hello = hello:{0}
Hellofile_zh_cn.properties
Hello = \u4f60\u597d: {0}
Struts2 for internationalization
1. Configuring the Struts.xml File
<!-- Find the configuration file to - < name= "Struts.custom.i18n.resources" value= "message"> </constant>
2. Build properties file name as Message
Message_en_us.properties--adduser = Add User Information
Message_zh_cn.properties--adduser = \u6dfb\u52a0\u7528\u6237
3, modify the register.jsp
< Center > < name= "AddUser"></s:text> </ Center>
4, according to the browser Httpheader, determine the output content
Java Learning Notes (9)--struts2 internationalization [1]