隨筆-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 閱讀(2070) 評論(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
          恩,我也在研究當中,有什么資料心得會第一時間跟大家分享的。  回復  更多評論
            
          主站蜘蛛池模板: 甘泉县| 西贡区| 喜德县| 苏尼特左旗| 余庆县| 和林格尔县| 南溪县| 贡嘎县| 绥德县| 古浪县| 紫云| 嘉荫县| 濮阳县| 平邑县| 甘孜| 江北区| 凯里市| 鹿邑县| 辽源市| 共和县| 甘孜县| 淳安县| 顺平县| 旺苍县| 图们市| 华阴市| 泗洪县| 察隅县| 博野县| 社旗县| 绿春县| 玉田县| 吉水县| 米泉市| 九龙城区| 集安市| 涟水县| 蒙城县| 周宁县| 东海县| 闵行区|