隨筆-348  評論-598  文章-0  trackbacks-0
          今天在做Roller開發(fā)的時(shí)候碰到了一個(gè)問題,就是Roller 4自帶的國際化文件中,中文的資源文件相比于英文的缺了不少條目,導(dǎo)致界面上很多地方都顯示的是英文,本來想一個(gè)一個(gè)復(fù)制然后翻譯的,發(fā)現(xiàn)條目太多了,就自己寫了一個(gè)合并和排序程序。

          下面這個(gè)是一個(gè)帶排序的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();
              }

          }

          然后在主程序里面寫了一個(gè)處理方法:
              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();
                  }

              }

          這樣就可以將中文資源文件中缺少的條目都復(fù)制過去并排序好,也方便我們的漢化翻譯。

          ---------------------------------------------------------
          專注移動開發(fā)

          Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
          posted on 2009-01-01 21:05 TiGERTiAN 閱讀(2070) 評論(2)  編輯  收藏 所屬分類: JavaRoller

          評論:
          # re: 如何對屬性資源文件進(jìn)行合并和排序(How to merge and sort the properties files)[未登錄] 2009-01-04 09:45 | haha
          不錯(cuò),roller一開始看了點(diǎn),但是后來沒接著看下去。呵呵。希望能在您的博客里面看到一些關(guān)于roller的架構(gòu),思想和流程業(yè)務(wù)等等方面的中文資料。謝謝!關(guān)注...  回復(fù)  更多評論
            
          # re: 如何對屬性資源文件進(jìn)行合并和排序(How to merge and sort the properties files)[未登錄] 2009-01-04 10:09 | tigertian
          @haha
          恩,我也在研究當(dāng)中,有什么資料心得會第一時(shí)間跟大家分享的。  回復(fù)  更多評論
            
          主站蜘蛛池模板: 巴马| 鄢陵县| 临沂市| 江达县| 嵊州市| 武汉市| 黄浦区| 龙山县| 新干县| 佛坪县| 衡山县| 兴安县| 安溪县| 怀集县| 渝中区| 化隆| 乌拉特后旗| 赤城县| 寿阳县| 宝山区| 镇沅| 博湖县| 涿州市| 教育| 镇远县| 巨野县| 青阳县| 博湖县| 安阳市| 台东市| 攀枝花市| 栾川县| 通道| 赤壁市| 克拉玛依市| 道孚县| 金门县| 东明县| 炉霍县| 龙里县| 金秀|