flex 绑定properties文件做国际化,以及ant编译
2008-08-28 14:28
579 查看
1.首先要想在flex builder 3里编辑properties文件,先要下载插件,步骤如下:
Help->Software Updates->Find and Install...->Search for new features to install 点击next.
点击"New Remote Site...",输入name:Arbitrary input, URL: http://propedit.sourceforge.jp/eclipse/updates/
一路回车安装之后会自动重启。ok,你现在就可以编辑properties文件了。
2.建议将国际化文件properties文件放到一个统一的目录,我这里放到property文件夹里,同时将此文件夹加入到flex build path的source path中
zh.properties代码如下
#注释
#
flex_label1=欢迎大家
flex_label2=各位好啊
flex_message={0}赶在{1}之前到的.
3.编写一个工具类来读取properties文件如下:
public class ResourceUtil extends EventDispatcher{
private static var _instance : ResourceUtil;
private var _language : String;
[ResourceBundle("en")]
private var lang_en:ResourceBundle;
[ResourceBundle("zh")]
private var lang_zh:ResourceBundle;
// [Bindable]
// private var localResources:ResourceBundle;
public static function getInstance() : ResourceUtil {
if (_instance == null) {
_instance = new ResourceUtil();
}
return _instance;
}
[Bindable(event="languageChange")]
public function getString(key:String):String {
return ResourceManager.getInstance().getString(_language,key);//localResources.getString(key);
}
/**
* get the substitute properties by key and other parameter
*/
[Bindable(event="languageChange")]
public function ResourceUtil(){
this.language = "zh";
}
public function set language(language : String):void {
this._language = language;
/*
if (_language == "en") {
this.localResources = lang_en;
} else if (_language == "zh") {
this.localResources = lang_zh;
} else {
this.localResources = lang_en;
} */
dispatchEvent(new Event("languageChange"));
}
}
4.在应用中就可以使用了
public function getSubstitute(key : String, ... rest):String
{
return StringUtil.substitute(ResourceManager.getInstance().getString(_language,key),rest);
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
<![CDATA[
import mx.resources.ResourceManager;
import com.ResourceUtil;
[Bindable]
private var ru : ResourceUtil = ResourceUtil.getInstance();
private function changeLanguage(language:String):void {
ru.language = language;
}
]]>
</mx:Script>
<mx:Label id="label1" x="10" y="10" text="{ru.getString('flex_label1')}" />
<mx:Label id="label2" x="10" y="38" text="{ru.getString('flex_label2')}"/>
<mx:Label id="label3" x="10" y="58" text="{ru.getSubstitute('flex_message','Anant', 'Nick')}" />
<mx:Button x="10" y="88" label="Chinese" click="changeLanguage('zh')"/>
<mx:Button x="88" y="88" label="English" click="changeLanguage('en')"/>
</mx:Application>
5.还要注意ant build 的时候
<target name="buildMain" depends="init">
<mxmlc file="${src.dir}/ResourceTest.mxml" output="${dest.dir}/ResourceTest.swf">
<load-config filename="${FLEX_CONFIG_FILE}"/>
<source-path path-element="${basedir}/property" />
</mxmlc>
</target>
Help->Software Updates->Find and Install...->Search for new features to install 点击next.
点击"New Remote Site...",输入name:Arbitrary input, URL: http://propedit.sourceforge.jp/eclipse/updates/
一路回车安装之后会自动重启。ok,你现在就可以编辑properties文件了。
2.建议将国际化文件properties文件放到一个统一的目录,我这里放到property文件夹里,同时将此文件夹加入到flex build path的source path中
zh.properties代码如下
#注释
#
flex_label1=欢迎大家
flex_label2=各位好啊
flex_message={0}赶在{1}之前到的.
3.编写一个工具类来读取properties文件如下:
public class ResourceUtil extends EventDispatcher{
private static var _instance : ResourceUtil;
private var _language : String;
[ResourceBundle("en")]
private var lang_en:ResourceBundle;
[ResourceBundle("zh")]
private var lang_zh:ResourceBundle;
// [Bindable]
// private var localResources:ResourceBundle;
public static function getInstance() : ResourceUtil {
if (_instance == null) {
_instance = new ResourceUtil();
}
return _instance;
}
[Bindable(event="languageChange")]
public function getString(key:String):String {
return ResourceManager.getInstance().getString(_language,key);//localResources.getString(key);
}
/**
* get the substitute properties by key and other parameter
*/
[Bindable(event="languageChange")]
public function ResourceUtil(){
this.language = "zh";
}
public function set language(language : String):void {
this._language = language;
/*
if (_language == "en") {
this.localResources = lang_en;
} else if (_language == "zh") {
this.localResources = lang_zh;
} else {
this.localResources = lang_en;
} */
dispatchEvent(new Event("languageChange"));
}
}
4.在应用中就可以使用了
public function getSubstitute(key : String, ... rest):String
{
return StringUtil.substitute(ResourceManager.getInstance().getString(_language,key),rest);
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
<mx:Script>
<![CDATA[
import mx.resources.ResourceManager;
import com.ResourceUtil;
[Bindable]
private var ru : ResourceUtil = ResourceUtil.getInstance();
private function changeLanguage(language:String):void {
ru.language = language;
}
]]>
</mx:Script>
<mx:Label id="label1" x="10" y="10" text="{ru.getString('flex_label1')}" />
<mx:Label id="label2" x="10" y="38" text="{ru.getString('flex_label2')}"/>
<mx:Label id="label3" x="10" y="58" text="{ru.getSubstitute('flex_message','Anant', 'Nick')}" />
<mx:Button x="10" y="88" label="Chinese" click="changeLanguage('zh')"/>
<mx:Button x="88" y="88" label="English" click="changeLanguage('en')"/>
</mx:Application>
5.还要注意ant build 的时候
<target name="buildMain" depends="init">
<mxmlc file="${src.dir}/ResourceTest.mxml" output="${dest.dir}/ResourceTest.swf">
<load-config filename="${FLEX_CONFIG_FILE}"/>
<source-path path-element="${basedir}/property" />
</mxmlc>
</target>
相关文章推荐
- 使用Ant编译出flex的swc文件
- Ant and Flex 用Ant编译MXML文件 - 蚂蚁咬断松紧带(^_^)
- 制作一个Flex AIR 程序调用 可执行程序(mxmlc.exe) 并且 生成.as文件并编译为.swf文件
- Struts2中常用的.properties文件、xml文件的命名方式、存放位置以及详解。
- ArrayList 与HashSet的比较,及应用反射读取properties配置文件中的数据进行实例化再调用,以及类加载器的使用;还有HashCode的分析,及导致内存泄露,内存溢出的原因之一
- Java中读取属性文件以及做资源国际化
- gulp 简单命令------sass文件编译css ----安装以及使用
- Linux编译多个不同目录下的文件以及静态库、动态库的使用
- 包含cpp文件链接opencv源码编译以及neon加速的Android.mk
- Ant命令编译flex时碰到的问题:[mxmlc] java.lang.OutOfMemoryError: Java heap space
- 【JAVA】Properties文件以及XML文件的读取操作
- Struts2中default.properties常量默认配置文件详解,以及修改常量方式
- Ant编译生成war文件的build.xml文件示例
- 用Java做国际化时,假如properties文件的属性值需要换行,如何处理?
- android下载编译以及文件系统提取总结
- delphi清理编译过程文件(*.dcu),以及垃圾文件*.~*
- Flex编译CSS资源与国际化
- 使用ant编译、运行junit、以及检查编码
- 用 ant 编译你的 flex 项目
- flex的mxml 文件在eclipse下不能自动编译的问题