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>
 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值