spring_02国际化支持
来源:互联网 发布:你的眼神网络歌手 编辑:程序博客网 时间:2024/05/27 20:09
核心思路:将程序中需要实现国际化的信息写入资源文件,代码中仅仅使用相应的个信息的key。
上代码!
首先建立两个文件,一个中文,一个英文。
message_en_US.properties
hello=welcome,{0}now=now is :{0}
message_zh_CN.properties
hello=欢迎你,{0}now=现在的时间是:{0}
beans.xml文件
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basenames"> <list> <value>message</value> </list> </property> </bean>
建立一个测试类
package com.test;import java.util.Date;import java.util.Locale;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Test02 { public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml"); String hello = ctx.getMessage("hello", new String []{"猴子"}, Locale.getDefault(Locale.Category.FORMAT)); String now = ctx.getMessage("now",new Object[]{new Date()} , Locale.getDefault(Locale.Category.FORMAT)); System.out.println(hello); System.out.println(now); }}
输出结果
欢迎你, 猴子
现在的时间是: 17-4-14 下午4:28
在英文环境下,输出的就是英文版的咯!
0 0
- spring_02国际化支持
- Spring_02
- 关于Spring_02
- 初识Spring_02
- qt支持中文、国际化
- Websharp 8 - 国际化支持
- gSOAP的国际化支持
- 批处理文件国际化支持解决方案
- asp.net国际化支持
- Application支持国际化
- wince国际化语言支持
- Struts2 配置国际化支持
- Struts 2国际化支持
- Struts2的国际化支持
- Struts2的国际化支持
- struts的国际化支持
- struts2 的国际化支持
- struts2 的国际化支持
- Android之Activity生命周期及启动模式
- 2017年会是Serverless爆发之年吗?
- 序列化
- Linux 内核网络协议栈 ------sk_buff 结构体 以及 完全解释 (2.6.16)
- Java中使用try...catch以及try...catch...finally捕获异常
- spring_02国际化支持
- [树套树] BZOJ3196: 二逼平衡树
- 词向量之word2vec(1)
- MD5大概简述
- pyqtgraph如何设置字符串类型横坐标
- 谈谈移动硬盘或者手机连接到PC提示“无法访问,拒绝访问”或“您没有访问该设备的权限”的解决办法
- android 系统架构分析
- C++复习之友元和const修饰类成员
- Head First SQL 第五章