1. I18N原理
a) ResourceBundle和Locale的概念
b) 资源文件
c) native2ascii
//test.java
import java.util.Locale; import java.util.ResourceBundle; public class Test { public static void main(String[] args) { ResourceBundle res = ResourceBundle.getBundle("app", Locale.CHINA); System.out.println(res.getString("welcome.msg" )); } }
//app_en_US.properties
welcome.msg=hello,sir
//app.zh_CHINA.properties
welcome.msg=\u6b22\u8fce\u4f60\uff01
2.Struts的资源文件
a) Action – Package – App级
b) 一般只用APP
i. struts.xml custom.i18n
<constant name="struts.custom.i18n.resources" value="bbs2009"></constant>
c) PropertiesEditor插件
i. 解压
ii. features plugin 覆盖到myeclipse中的eclipse目录里
d) 动态语言切换
i. request_locale=en_US
<form action="admin/Login-login" method="post"> <s:property value="getText('login.username')"/> <input name="username" /> <s:property value="getText('login.password')"/><input name="password" type="password" /> <input type="submit" value="<s:property value="getText('login.login')"/>" /> </form> <s:debug></s:debug> <a href="admin/lang?request_locale=en_US">en</a> <a href="admin/lang?request_locale=zh_CN">cn</a>