badqiu

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

          flex國際化

          準(zhǔn)備:

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

           

          項(xiàng)目中增加國際化

          一.配置

          目錄結(jié)構(gòu):

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

           

           message.properties內(nèi)容使用UTF-8編碼.

           

          開發(fā)環(huán)境配置:

          在Eclipse開發(fā)環(huán)境中的Flex Compiler/Additional compiler arguments選項(xiàng)

          增加如下參數(shù)

           

          -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這個(gè)變量,可以使用ResourceManager.getInstance()代替resourceManager,因?yàn)镽esourceManager是單態(tài)的。

           

          編譯檢查: 

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

           

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

           

          三.動(dòng)態(tài)修改當(dāng)前語言

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

           

          四.減少編譯大小

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

          main_zh_CN.swf  
          main_en_US.swf  

           

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

          當(dāng)然這樣處理會(huì)麻煩一點(diǎn),請具體參考你編譯出來的swf大小,相差不大的請也可以忽略此項(xiàng)。

           

           

          五. 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" />

                  
          <!-- 具體編譯參數(shù)請參考: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}"/>

                      
          <!-- 消除編譯警告,允許源代碼路徑重疊或是包含現(xiàn)象 -->
                      
          <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)  編輯  收藏


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 沅江市| 菏泽市| 大化| 松阳县| 酒泉市| 海门市| 扶沟县| 南雄市| 南溪县| 乌苏市| 历史| 简阳市| 渑池县| 乡宁县| 新和县| 明星| 沂南县| 新竹市| 昌乐县| 宁陕县| 通榆县| 湖北省| 鹿泉市| 莱芜市| 大方县| 博客| 南开区| 连江县| 长武县| 卢龙县| 新昌县| 威远县| 上思县| 措美县| 华宁县| 苍溪县| 招远市| 巴林左旗| 郑州市| 苏尼特右旗| 深圳市|