badqiu

          XPer
          隨筆 - 46, 文章 - 3, 評論 - 195, 引用 - 0
          數據加載中……

          flex國際化

          準備:

          flex3只支持兩種語言,en_US,ja_JP,而flex4中則支持多國語言,所以可以將flex4中的%FLEX_HOME%\frameworks\locale\zh_CN拷貝至flex3中。

           

          項目中增加國際化

          一.配置

          目錄結構:

          flex_src
              --locale
                  --zh_CN
                         message.properties
                  --en_US
                         message.properties

           

           message.properties內容使用UTF-8編碼.

           

          開發環境配置:

          在Eclipse開發環境中的Flex Compiler/Additional compiler arguments選項

          增加如下參數

           

          -locale zh_CN -locale en_US -source-path=locale/{locale}

           

           

          二.使用國際化

           

          Flex中提供了兩種方法使用本地化文件:

          1.使用@Resource

          <mx:Label text="@Resource(key='name', bundle='message')"/>

           

          其中 key 表示的是要取資源的 key , bundle 表示的是本地化文件,去掉 .properties 之后的名稱

           

          2.使用 ResourceManager

          <mx:Label text="resourceManager.getString("bundleName","key")"/>

           

          注意:如果容器中沒有resourceManager這個變量,可以使用ResourceManager.getInstance()代替resourceManager,因為ResourceManager是單態的。

           

          編譯檢查: 

          使用[ResourceBundle('message')]可以為編譯器提供編譯檢查,實際不需要指定這個也是可以的。

           

          <mx:Metadata>
          [ResourceBundle('message')]
          </mx:Metadata>

           

          三.動態修改當前語言

          ResourceManager.getInstance().localeChain = ['zh_CN'];  

           

          四.減少編譯大小

          由于flex是使用編譯器將國際化信息編譯進swf中,所以如果將所有的語言全部編譯進swf,會導致swf文件過于龐大。而正如國內的環境,如果你的用戶大部分都是中文用戶,實在沒有必要為了少量英文用戶而增加swf文件的大小。 所以最好的效果是 *獨立編譯*。即編譯出:

          main_zh_CN.swf  
          main_en_US.swf  

           

           參考: http://www.nbilyk.com/flex-localization-example

          當然這樣處理會麻煩一點,請具體參考你編譯出來的swf大小,相差不大的請也可以忽略此項。

           

           

          五. ant編譯

              <property name="FLEX_HOME" value="${env.FLEX_HOME}"/>
              
          <property name="FLEX_SWC" value="${basedir}/flex_libs"/>
              
          <property name="FLEX_SRC" value="${basedir}/flex_src"/>

              
          <target name="compile-flex">
                  
          <echo message="FLEX_HOME:${FLEX_HOME}"/>

                  
          <!-- tasks: mxmlc,compc,html-wrapper -->
                  
          <taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />

                  
          <!-- 具體編譯參數請參考:http://www.k-zone.cn/zblog/post/flex-compiler-parameter.html -->
                  
          <mxmlc
                      
          file="${basedir}/flex_src/${flex.application.name}.mxml"
                      output
          ="${basedir}/dist/web/flex/${flex.application.name}.swf"
                      actionscript-file-encoding
          ="UTF-8"
                      keep-generated-actionscript
          ="false"
                      incremental
          ="true"
                      compiler.show-actionscript-warnings
          ="true"
                      compiler.show-binding-warnings
          ="true"
                      compiler.show-unused-type-selector-warnings
          ="true"
                      compiler.strict
          ="true">

                      
          <!-- Get default compiler options. -->
                      
          <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>

                      
          <!-- List of path elements that form the roots of ActionScript class    hierarchies. -->
                      
          <source-path path-element="${FLEX_SRC}"/>
                      
          <!-- 需要編譯的locale -->
                      
          <locale>zh_CN</locale>
                      
          <locale>en_US</locale>
                      
          <source-path path-element="${FLEX_SRC}/locale/{locale}"/>

                      
          <!-- 消除編譯警告,允許源代碼路徑重疊或是包含現象 -->
                      
          <allow-source-path-overlap>true</allow-source-path-overlap>

                        
          <!-- List of SWC files or directories that contain SWC files. -->
                      
          <compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
                          
          <include name="libs" />
                          
          <include name="locale/{locale}" />
                      
          </compiler.library-path>
                      
          <!-- 自定義或第三方包 -->
                      
          <compiler.library-path dir="${basedir}" append="true">
                          
          <include name="flex_libs" />
                      
          </compiler.library-path>

                      
          <compiler.debug>false</compiler.debug>
                  
          </mxmlc>

              
          </target>

          posted on 2010-02-08 16:09 badqiu 閱讀(3301) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 南华县| 洛南县| 泰安市| 赞皇县| 丰城市| 博乐市| 卫辉市| 浏阳市| 天峨县| 晴隆县| 天柱县| 合山市| 永顺县| 汤阴县| 双峰县| 汉寿县| 镇平县| 客服| 乐至县| 海盐县| 吴堡县| 怀宁县| 通榆县| 神木县| 陈巴尔虎旗| 桑植县| 延庆县| 莱阳市| 和静县| 孝感市| 普格县| 新晃| 鸡西市| 马鞍山市| 蕲春县| 绥宁县| 长岛县| 靖安县| 三河市| 横山县| 南华县|