第一、 创建在com.message包中创建front.properties和front_zh_CN.properties两个文件
front_zh_CN.properties中内容如下:
user.login.err=/u7528/u6237/u540D/u6216/u5BC6/u7801/u9519/u8BEF
front.properties中内容如下:
user.login.err=username or password error
第二、 然后在applicationContext.xml中创建消息bean
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>com.message.front</value>
</list>
</property>
</bean>
第三、 方法:
private static final Locale newLocale = new Locale("zh","CN");
private static ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
public static String getMessage(String key, Object[] object, Locale locale) {
return ctx.getMessage(key, object, locale);
}
第四、 调用:
String message=getMessage(“user.login.err”, null, request);
第五、 国际化编辑插件ResourceBundleEditor
首先下载该插件(ResourceBundleEditor_v0.7.7.zip),网上有丰富的下载资源,文件名ResourceBundleEditor_v0.7.7.zip。
下载后解压,会产生一个plugins文件夹,把该文件复制粘贴到eclipse下,覆盖原文件。
之后用MyEclipse运行项目,选择ApplicationResources.properties点鼠标右键,选择Open with下的ResourceBundle Editor。会自动打开该插件。
如图
你只需要选择你想要实现的语言的国家,他就会帮你自动生成一个Properties文件,例如如图所示会自动生成
ApplicationResources_zh_CN.Properties文件,然后在根据每个属性值,写入自己想要在页面上显示的语言就可以,好了插件介绍完毕了。
本文介绍的仅限于MyEclipse6.5之前的版本,MyEclipse6.5已经有了写入中文自动转码的功能,但是对于大量属性的处理,这个插件还是会
方便很多。因为他可以自动生成相应的Properties文件。