今天学习了一下如何在编写properties文件的时候编写任何的国家的语言,这个可能在Andorid中会用到,或者以防以后在Struts2中用到
先看一段代码:
package org.hualang.i18n;
import java.util.Locale;
import java.util.ResourceBundle;
public class MainPage {
public static void main(String[] args) {
ResourceBundle res = ResourceBundle.getBundle("app", Locale.CHINA);
System.out.println(res.getString("message"));
}
}
app_zh_CN.properties
message=成功了
app_en_US.properties
message=Test successful!
运行结果:
成功了
如果想显示英文的话,就将Locale.CHINA中的CHINA改为US,这样程序就会默认匹配的是app_en_US.properties文件
显示:Test successful!
这里需要注意的几点:
①properties文件默认放在程序的包外面,src里面
②如果直接在app_zh_CN.properties写入中文的话,由于eclipse默认的编码是ISO-8859-1,所以不会让你保存,而且即使保存了,也会出现乱码。这时有两种方法解决
(1)进入DOS,进入/I18NTest/src目录下,输入如下:
src>c:\jdk1.6\bin\native2ascii
输入一个中文,比如你好
会出现一个对应的编码
然后再输入
>c:\jdk1.6\bin\native2ascii app_zh_CN_temp.properties app_zh_CN.properties
这样就将app_zh_CN_temp.properties转换为了可以输入中文的properties文件了
但是这样有个缺点,麻烦,每次如果写不同国家的properties时候,每次都要这样写,会很麻烦
(2)用eclipse插件,名字叫做jp_1_.gr.java_conf.ussiy.app.propedit_5.3.3
将其解压后,将features和plugins里面的文件覆盖到你的eclipse或者myeclipse文件夹下。然后重启eclipse,选中
app_zh_CN.properties右键,用PropertiesEditor打开即可,这样就可以往里面输入中文了,而且也会正常显示
注意:eclipse之前自带的propertiesEditor不能写入中文
分享到:
相关推荐
struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...
struts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jarstruts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jar
赠送jar包:struts2-json-plugin-2.3.24.jar; 赠送原API文档:struts2-json-plugin-2.3.24-javadoc.jar; 赠送源代码:struts2-json-plugin-2.3.24-sources.jar; 赠送Maven依赖信息文件:struts2-json-plugin-...
struts2-json-plugin,Struts JSON插件
struts2-ssl-plugin-1.2.1.jar
struts2-convention-plugin-2.3.32
struts2-dojo-plugin-2.3.4 jar 日期控件的jar包 需要的自行下载
struts2-convention-plugin-2.3.15.1.jar
struts2-core-2.2.3.1-sources.jar struts2-core-2.2.3.1-sources.jar struts2-core-2.2.3.1-sources.jar
struts2-dojo-plugin-2.2.1.jar, 直接导入到Struts2项目里即可,注意版本。
struts2-convention-plugin-2.3.24.1
struts2国际化_i18n 完整实例。欢迎下载。
struts2-dojo-plugin-2.3.15.3.jar.zip
struts2-core-2.5.18.jar包下载,支持struts2的类库下载
struts2 国际化 i18n struts2 国际化 i18n struts2 国际化 i18n
struts2-jquery-plugin-3.1.0.jar
struts2-core-2.5.10.jar ,struts核心包,struts2-core-2.5.10.jar
struts2-jfreechart-plugin-2.1.8.1.jar
默认的struts2-config-browser-plugin包中的ftl文件include标签路径用的相对路径,会找到包内的include文件,将包内ftl里include的路径改成的/开头的全路径。
struts2-convention-plugin-2.1.6.jar