STRUTS2 国际化:
1:I18N原理
package com.struts2.util;
import java.util.Locale;
import java.util.ResourceBundle;
public class I18NDemo {
public static void main(String []args) {
ResourceBundle resBundle = ResourceBundle.getBundle("bbs2011", Locale.US);
System.out.println(resBundle.getString("resource.title"));
}
}
2:国际化资源文件
优先级为:Application>Pagckage>Action的优先级,资源文件中的参数填入值使用
在Action中使用国际化资源文件必须使用对应的XxxAction文件中的Xxx_zh_CN.properties,Xxx_en_US.properties;
在Package中使用国际化资源文件必须使用对应的package_zh_CN.properties,package_en_US.properties;作为包命名。
在Application中使用可以命名为xxx_zh_CN.properties,xxx_en_US.properties;
<constact mode="struts"></constact>
在struts2中可以使用 <s:text name="welcome.msg"><s:param value="msg.title"/></s:text>
使用上面的<s:text name="welcome.msg"><s:param value=""></s:param></s:text>传递资源文件中的占位符,如:此处可以使用{0},还可以使用{1};<s:param>传递参数
3:动态语言切换
使用request_locale=zh_CN ,request_locale=en_US