Enjoy yourself,and don't care about others' thinking!
----TiGERTiAN
BlogJava
首页
新随笔
联系
聚合
管理
随笔-348 评论-598 文章-0 trackbacks-0
如何对属性资源文件进行合并和排序(How to merge and sort the properties files)
今天在做Roller开发的时候碰到了一个问题,就是Roller 4自带的国际化文件中,中文的资源文件相比于英文的缺了不少条目,导致界面上很多地方都显示的是英文,本来想一个一个复制然后翻译的,发现条目太多了,就自己写了一个合并和排序程序。
下面这个是一个带排序的Properties类(SortedProperties)
package
com.gcoresoft.utils;
import
java.util.Collections;
import
java.util.Enumeration;
import
java.util.Properties;
import
java.util.Vector;
/** */
/**
*
* TODO 带排序的配置文件类
*
*
@author
<a href="mailto:tianlu@jsecode.com">tianlu</a>
*
@version
$Rev$ <br>
* $Id$
*/
public
class
SortedProperties
extends
Properties
{
public
synchronized
Enumeration keys()
{
Enumeration keysEnum
=
super
.keys();
Vector keyList
=
new
Vector();
while
(keysEnum.hasMoreElements())
{
keyList.add(keysEnum.nextElement());
}
Collections.sort(keyList);
return
keyList.elements();
}
}
然后在主程序里面写了一个处理方法:
public
static
void
updateApplicationResources()
{
try
{
String path
=
Utils.
class
.getResource(
"
/
"
).getPath();
String cnFilePath
=
path
+
"
ApplicationResources_zh_CN.properties
"
;
ResourceBundle enBundle
=
ResourceBundle.getBundle(
"
ApplicationResources
"
);
Properties cnProp
=
new
SortedProperties();
InputStream cnInput
=
new
FileInputStream(cnFilePath);
cnProp.load(cnInput);
cnInput.close();
Enumeration
<
String
>
enu
=
enBundle.getKeys();
while
(enu.hasMoreElements())
{
String key
=
enu.nextElement();
cnProp.setProperty(key, enBundle.getString(key));
}
OutputStream output
=
new
FileOutputStream(cnFilePath);
cnProp.store(output,
""
);
output.close();
}
catch
(Exception e)
{
e.printStackTrace();
}
}
这样就可以将中文资源文件中缺少的条目都复制过去并排序好,也方便我们的汉化翻译。
---------------------------------------------------------
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2009-01-01 21:05
TiGERTiAN
阅读(2047)
评论(2)
编辑
收藏
所属分类:
Java
、
Roller
评论:
#
re: 如何对属性资源文件进行合并和排序(How to merge and sort the properties files)[未登录] 2009-01-04 09:45 |
haha
不错,roller一开始看了点,但是后来没接着看下去。呵呵。希望能在您的博客里面看到一些关于roller的架构,思想和流程业务等等方面的中文资料。谢谢!关注...
回复
更多评论
#
re: 如何对属性资源文件进行合并和排序(How to merge and sort the properties files)[未登录]
2009-01-04 10:09 |
tigertian
@haha
恩,我也在研究当中,有什么资料心得会第一时间跟大家分享的。
回复
更多评论
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
知识库
C++博客
博问
管理
相关文章:
OSGi and Hadoop and Node.js
javacc工具小记
MyEclipse 6.5新序列号,到2013年
OtaNotifier.java
Java中无符号整数
C#的BinaryWriter和Java的DataInputStream之间的数据相互转换
在Mac下面下载Android源代码
[转]Java通过XML Schema校验XML
[转]JAVA上加密算法的实现用例
LG GW880(Ophone)开启ADB调试模式
专注移动开发--Windows Mobile, Android, iPhone, J2ME, BlackBerry, Symbian, Windows Phone
慢慢混,慢慢学
<
2009年1月
>
日
一
二
三
四
五
六
28
29
30
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
常用链接
我的随笔
我的评论
我的参与
最新评论
留言簿
(40)
给我留言
查看公开留言
查看私人留言
随笔分类
(402)
Ajax(4)
Android(58)
BlackBerry(8)
C/C++(3)
Design Patterns(6)
Discuz!NT(1)
DotNet(26)
Feeling(61)
Flex(4)
Grails(2)
Hibernate(1)
iPhone(5)
J2ME(11)
Java(99)
JSF(26)
Linux(18)
MapXtreme(9)
Objective c(1)
Oracle(6)
Other technique(20)
Perl/Python(1)
Roller (10)
Symbian
VB/ASP(7)
WebWork(3)
Windows Mobile(10)
WindowsPhone(2)
随笔档案
(306)
2017年5月 (1)
2016年8月 (1)
2015年11月 (1)
2015年2月 (1)
2015年1月 (1)
2013年12月 (1)
2013年5月 (1)
2013年4月 (1)
2012年9月 (1)
2012年7月 (1)
2012年6月 (1)
2012年5月 (2)
2012年4月 (1)
2012年2月 (2)
2012年1月 (1)
2011年11月 (2)
2011年10月 (1)
2011年9月 (1)
2011年8月 (2)
2011年7月 (3)
2011年6月 (2)
2011年3月 (3)
2011年2月 (4)
2011年1月 (15)
2010年12月 (1)
2010年11月 (2)
2010年10月 (6)
2010年9月 (12)
2010年8月 (3)
2010年7月 (2)
2010年6月 (6)
2010年5月 (14)
2010年4月 (7)
2010年3月 (16)
2010年2月 (10)
2010年1月 (14)
2009年12月 (12)
2009年11月 (5)
2009年10月 (3)
2009年9月 (2)
2009年8月 (3)
2009年6月 (1)
2009年4月 (2)
2009年3月 (2)
2009年1月 (3)
2008年12月 (3)
2008年11月 (20)
2008年10月 (17)
2008年9月 (3)
2008年4月 (1)
2008年3月 (2)
2008年2月 (8)
2008年1月 (1)
2007年11月 (2)
2007年10月 (13)
2007年9月 (3)
2007年7月 (4)
2007年6月 (2)
2007年5月 (12)
2007年4月 (15)
2007年3月 (6)
2007年2月 (2)
2007年1月 (1)
2006年7月 (2)
2006年4月 (1)
2006年1月 (1)
2005年11月 (1)
2005年8月 (1)
2005年7月 (9)
相册
我正在读的书
我的好友们
JavaBy
有心就有翼 有梦就会飞--MC
搜索
积分与排名
积分 - 804774
排名 - 50
最新评论
1. re: Hibernate三种状态的区分,以及save,update,saveOrUpdate,merge等的使用[未登录]
哈哈~
--a
2. re: onInterceptTouchEvent和onTouchEvent调用时序
@米其林的微笑
在你的子view重写ontouchevent方法就行
--kxt
3. re: Android弹出拨号界面和拨打电话实现
这找不到call是怎么回事?现在有别的方法实现这个功能吗?
--firetomato
4. re: Android弹出拨号界面和拨打电话实现
请我dial和call方法有什么区别么?
--jaime
5. re: Android文字跑马灯控件(文本自动滚动控件)
如何让滚动的速度快一点啊??
--学鸟
阅读排行榜
1. onInterceptTouchEvent和onTouchEvent调用时序(38656)
2. Android的Intent和IntentFilter应用说明一例(37690)
3. Hibernate三种状态的区分,以及save,update,saveOrUpdate,merge等的使用(34286)
4. Android中短信拦截解决方案(31058)
5. Android中ContentProvider和ContentResolver使用入门(21406)
评论排行榜
1. 【JSF】Richfaces复选框树(Checkbox tree)的权限分配的解决方案(69)
2. JSF中动态生成HtmlMessage控件出错的解决办法(38)
3. hibernate中at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)异常的解决方法(27)
4. 这两天用Flex写了一个多媒体播放器(19)
5. Android文字跑马灯控件(文本自动滚动控件)(17)