我在E盘根目录下建一个.txt文件,里面分别写了username=用户名,
userpwd1=密码,
userpwd2=确认密码
最后保存为globalMessages.properties,在dos中输入e:后跳到E盘根目录,然后输入E:\>java\bin\native2ascii globalMessages.properties globalMessages_zh_CN.properties,的确在E盘根目录下生成一个globalMessages_zh_CN.properties文件,可里面的value值也不是unicode码啊,并且同样的方法生成的globalMessages_en_US.properties文件里也不是value值英文,这是怎么回事,刚接触struts2,不懂啊
userpwd1=密码,
userpwd2=确认密码
最后保存为globalMessages.properties,在dos中输入e:后跳到E盘根目录,然后输入E:\>java\bin\native2ascii globalMessages.properties globalMessages_zh_CN.properties,的确在E盘根目录下生成一个globalMessages_zh_CN.properties文件,可里面的value值也不是unicode码啊,并且同样的方法生成的globalMessages_en_US.properties文件里也不是value值英文,这是怎么回事,刚接触struts2,不懂啊
(1)页面国际化处理
(2)JAVA类的源代码处理
一、给如下资源文件添加需要国际化的内容 1、ApplicationResources.properties ApplicationResources_zh_CN.properties 中文 ApplicationResources_en_US.properties 英文
2、ApplicationResources.properties ApplicationResources_zh_CN.properties 中文 ApplicationResources_en_US.properties 英文
二、在strutis.xml文件中作如下配置
<message-resources parameter="resources.activetitle.ApplicationResources"/>
<message-resources parameter="resources.menutitle.GlobalUITitle" key='globaluititle'/>
<message-resources parameter="resources.menutitle.UITitle" key='uititle'/>
<message-resources parameter="resources.menutitle.MenuTitle" key='menutitle'/>
<message-resources parameter="resources.activetitle.ApplicationResources"></message-resources>
三、写Constants类里写处理资源文件及国际化的方法,主要用于在JAVA源代码中处理国际化问题
该类如下:
public class Constants {
public static MessageResources MESSAGE = MessageResources.getMessageResources("Reseveinfo"); public static MessageResources MESSAGE_UITITLE_RES = MessageResources .getMessageResources("resources.menutitle.UITitle"); public static MessageResources MESSAGE_GLOBAL_RES = MessageResources .getMessageResources("resources.menutitle.GlobalUITitle"); public static MessageResources MESSAGE_MENU_RES = MessageResources .getMessageResources("resources.menutitle.MenuTitle"); public static MessageResources MESSAGE_APP_RES = MessageResources .getMessageResources("resources.activetitle.ApplicationResources"); public static String [] disposeLanguage(Locale locale){
String []pagesign = new String[6]; pagesign[0] = MESSAGE_APP_RES.getMessage(locale, "pages.first"); pagesign[1] = MESSAGE_APP_RES.getMessage(locale, "pages.previous"); pagesign[2] = MESSAGE_APP_RES.getMessage(locale, "pages.next"); pagesign[3] = MESSAGE_APP_RES.getMessage(locale, "pages.end"); pagesign[4] = MESSAGE_APP_RES.getMessage(locale, "pages.no"); pagesign[5] = MESSAGE_APP_RES.getMessage(locale, "pages.page"); return pagesign; } // 处理语言国际化 public static String disposeLanguageApp(Locale locale,String str,Object [] args){ String retStr=""; if(locale == null || StringUtils.isEmpty(str)) return retStr; if(args == null){ retStr=MESSAGE_APP_RES.getMessage(locale,str); }else{ retStr=MESSAGE_APP_RES.getMessage(locale,str,args); } retStr=StringUtils.isEmpty(retStr) ? "" : retStr;
return retStr;
}
// 处理语言国际化
public static String disposeLanguageApp(Locale locale,String str){
String retStr = "";
if (locale == null || StringUtils.isEmpty(str))
return retStr;
retStr = MESSAGE_APP_RES.getMessage(locale, str);
retStr = StringUtils.isEmpty(retStr) ? "" : retStr;
return retStr;
}// 处理语言国际化 public static String disposeLanguageUititle(Locale locale,String str,Object [] args){
String retStr="";
if(locale == null || StringUtils.isEmpty(str))
return retStr;
if(args == null){
retStr=MESSAGE_UITITLE_RES.getMessage(locale,str);
}else{
retStr=MESSAGE_UITITLE_RES.getMessage(locale,str,args);
}
retStr=StringUtils.isEmpty(retStr) ? "" : retStr
return retStr;
}
// 处理语言国际化
public static String disposeLanguageUititle(Locale locale,String str){
String retStr = "";
if (locale == null || StringUtils.isEmpty(str))
return retStr;
retStr = MESSAGE_UITITLE_RES.getMessage(locale, str);
retStr = StringUtils.isEmpty(retStr) ? "" : retStr;
return retStr; }// 处理语言国际化
public static String disposeLanguageGlobal(Locale locale,String str,Object [] args){
String retStr="";
if(locale == null || StringUtils.isEmpty(str))
return retStr;
if(args == null){
retStr=MESSAGE_GLOBAL_RES.getMessage(locale,str);
}else{
retStr=MESSAGE_GLOBAL_RES.getMessage(locale,str,args);
}
retStr=StringUtils.isEmpty(retStr) ? "" : retStr;
return retStr;
}// 处理语言国际化
public static String disposeLanguageGlobal(Locale locale,String str){
String retStr = "";
if (locale == null || StringUtils.isEmpty(str))
return retStr;
retStr = MESSAGE_GLOBAL_RES.getMessage(locale, str);
retStr = StringUtils.isEmpty(retStr) ? "" : retStr;
return retStr; } // 处理语言国际化
public static String disposeLanguageMenu(Locale locale,String str,Object [] args){
String retStr="";
if(locale == null || StringUtils.isEmpty(str))
return retStr;
if(args == null){
retStr=MESSAGE_MENU_RES.getMessage(locale,str);
}else{
retStr=MESSAGE_MENU_RES.getMessage(locale,str,args);
}
retStr=StringUtils.isEmpty(retStr) ? "" : retStr;
return retStr; }// 处理语言国际化
public static String disposeLanguageMenu(Locale locale,String str){ String retStr = "";
if (locale == null || StringUtils.isEmpty(str))
return retStr;
retStr = MESSAGE_MENU_RES.getMessage(locale, str);
retStr = StringUtils.isEmpty(retStr) ? "" : retStr;
return retStr; }
} //=========================================================================================== 例如:在JAVA源代码中处理国际化问题 ui.title.log.page.usercode=用户代码
Constants.disposeLanguageUititle(locale,"ui.title.log.page.usercode"))); //"用户代码" 四、处理JSP页面的国际化问题
ui.title.order.orderid=订单号
<bean:message key="ui.title.order.orderid" bundle="uititle"/>
<bean:message bundle="uititle" key="ui.title.order.orderid"> </bean:message>
注:在标签 <bean:message 中的bundl属性的值是
<message-resources parameter="resources.menutitle.UITitle" key='uititle'/>
中的 key值
<message-resources key="uititle" parameter="resources.menutitle.UITitle"></message-resources>
内容为:username=姓名
password=密码然后进入dos,在bin目录下敲入:native2ascii a_zh_CN.properties a.properties
之后生成a.properties文件,
内容为:username=\u59d3\u540d
password=\u5bc6\u7801转换成功!
内容为:username=姓名
password=密码然后进入dos,在bin目录下敲入:native2ascii a_zh_CN.properties a.properties
之后生成a.properties文件,
内容为:username=\u59d3\u540d
password=\u5bc6\u7801转换成功!