随笔-348  评论-598  文章-0  trackbacks-0
今天在做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)  编辑  收藏 所属分类: JavaRoller

评论:
# 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
恩,我也在研究当中,有什么资料心得会第一时间跟大家分享的。  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: