先说编译到主程序中去的方法:

1.创建资源文件夹

譬如可以在src文件夹下创建Locale文件夹,然后在此文件夹再次创建每个地区的资源文件夹,譬如de_DE,zh_CN.

然后分别创建后缀名为.properties的资源文件,分别放到各个地区的文件夹中。资源文件是可以包括任何事情,从字符串,数字,格式化和图片到样式。每个地区可以生成一个单独的文件。参考:CreateLocaleFiles.png

2.创建资源文件

创建了名为resources.properties的资源文件,内容为:

Properties代码

 ## resources.properties file for locale de_DE ##   

 # contact-form labels and assets
contact.title=Contact Form
contact.flagImg=assets/us.gif
contact.submit=Submit # contact-form fields
contact.field.name=Name
contact.field.streetAddress=Street Address
contact.field.city=City
contact.field.state=State
contact.field.zipCode=ZIP Code
contact.field.country=Country

3.创建mxml文件

Flex代码

 <?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" width="100%" height="100%">
<fx:Metadata>
[ResourceBundle("resources")]
</fx:Metadata>
<fx:Script>
<![CDATA[
private var locales:Array = [{label:"English (United States)", locale:"en_US"},
{label:"中文 (中国)", locale:"zh_CN"},
{label:"German (Denmark)", locale:"de_DE"},
{label:"French (France)", locale:"fr_FR"},
{label:"Japanese (Japan)", locale:"ja_JP"}]; private function comboChangeHandler():void
{
resourceManager.localeChain = [localeComboBox.selectedItem.locale];
}
]]>
</fx:Script> <s:Panel title="{resourceManager.getString('resources','contact.title')}" color="black" borderAlpha="0.15" width="350">
<s:layout>
<s:VerticalLayout horizontalAlign="center" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10" />
</s:layout> <mx:Form width="100%" color="0x323232">
<mx:FormItem label="{resourceManager.getString('resources','contact.field.name')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.streetAddress')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.city')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.state')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.zipCode')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.country')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem>
<s:Button label="{resourceManager.getString('resources','contact.submit')}" />
</mx:FormItem>
</mx:Form>
</s:Panel>
<mx:Spacer height="15" /> <s:HGroup width="350" verticalAlign="middle">
<mx:Spacer width="100%" />
<mx:Image source="{resourceManager.getString('resources','contact.flagImg')}"/>
<mx:ComboBox id="localeComboBox" dataProvider="{locales}" change="comboChangeHandler()"/>
</s:HGroup>
</s:VGroup>

4.配置Flex 编译参数

选中项目名称右键-Properties-Flex Complier-Addtional compiler arguments中添加

  1. -locale=en_US,zh_CN -allow-source-path-overlap=true -source-path=Locale/{locale}

这样就可以了,你可以通过切换发现可以实现国际化了,哈哈,不过只有两种地区的简单demo。

再谈谈用module分别加载不同地区资源

到底怎样加载这些资源文件决定于你的程序许多支持多少地区本地化。

a.如果你仅仅只是支持一到两个地区的本地化,那么一般来说就是直接编译到程序中。

b.如果要支持很多种本地化,一般选择在运行时加载所需的本地化资源。资源模块和编译入主程序相比,资源模块是一种比较好的本地化方式,因为它指定的资源模块可以在运行时加载。这样可以减小主程序的文件大小,但是如你所见你必须为每个资源模块加载一个单独的swf文件。这样的话会增加网络请求并且合成的主程序的大小比直接编译入主程序的方式更大。尽管如此,如果你有很多本地化的需求,分别单独的加载它们从长远来看会节省资源。

1.2 和上面一样

3.建立mxml文件

Mxml代码

 <?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
width="100%"
height="100%"
creationComplete="initApp()">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ResourceEvent;
import mx.resources.ResourceBundle; [Bindable]
private var locales:Array = [ "zh_CN","de_DE" ]; private function initApp():void {
/* Set the index to -1 so that the prompt appears
when the application first loads. */
localeComboBox.selectedIndex = -1;
} private function registrationComplete():void {
Alert.show(resourceManager.getString('resources', 'thanks'));
} private function comboChangeHandler():void {
var newLocale:String = String(localeComboBox.selectedItem); /* Ensure that you are not loading the same resource module more than once. */
if (resourceManager.getLocales().indexOf(newLocale) != -1) {
completeHandler(null);
} else {
// Build the file name of the resource module.
var resourceModuleURL:String = newLocale + "_ResourceModule.swf"; var eventDispatcher:IEventDispatcher =
resourceManager.loadResourceModule(resourceModuleURL);
eventDispatcher.addEventListener(ResourceEvent.COMPLETE, completeHandler);
}
} private function completeHandler(event:ResourceEvent):void {
resourceManager.localeChain = [ localeComboBox.selectedItem ]; /* This style is not bound to the resource bundle, so it must be reset when
the new locale is selected. */
var test:String = resourceManager.getString('resources','contact.field.city');
b1.setStyle("downSkin", resourceManager.getClass("RegistrationForm", "flag"));
}
]]></fx:Script>
<s:Image source="{resourceManager.getClass('resources', 'flag')}"/>
<mx:ComboBox id="localeComboBox"
prompt="Select One..."
dataProvider="{locales}"
change="comboChangeHandler()"/>
<mx:Form width="100%" color="0x323232">
<mx:FormItem label="{resourceManager.getString('resources','contact.field.name')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.streetAddress')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.city')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.state')}">
<s:TextInput />
</mx:FormItem>
<mx:FormItem label="{resourceManager.getString('resources','contact.field.zipCode')}">
<s:TextInput />
</mx:FormItem>
<!--<mx:FormItem label="@Resource(key='contact.field.zipCode', bundle='resources')">
<s:TextInput />
</mx:FormItem>-->
<mx:FormItem>
<s:Button label="{resourceManager.getString('resources','contact.submit')}" />
</mx:FormItem>
</mx:Form> <s:Button id="b1"
label="{resourceManager.getString('resources','submit_button')}"
click="registrationComplete()"/>
</s:VGroup>

4.确定需要哪些资源束

在你编译资源模块之前,你必须知道那些资源束应该放到它里面。换句话说,你必须要知道那些资源是你的主程序-包括它的框架-真正需要的。这不仅仅包括你所创建程序需要的的资源,而且也包括程序框架需要的资源。

在你的flex bulider中找到mxmlc.exe 文件,例如我的在:C:\Program Files\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\bin,执行

当你使用resource-bundle-list选项时,你还必须设置locale的值为空。

myresource.txt 就是待会要把你所有要国际化的页面和框架所需的所有文件名输出到这个文件中,地址就在mxmlc.exe文件的同一目录

F:\demo\Demo\src\view\resource\ResourceMoudleDemo.mxml 就是你要国际化的页面的绝对路径

执行完后到myresource.txt中查看,内容为:

其中的resources就是自定义的资源文件,其他就是框架所用的文件了

5.把所有的文件都编译到一个swf中

  1. mxmlc -locale=de_DE
  2. -source-path=F:\demo\Demo\src\Locale\{locale} -include-resource-bundles=resources,collections,components,containers,controls,core,effects,layout,skins,styles,
  3. textLayout -output de_DE_ResourceModule.swf

这个时候就会在mxmlc.exe中相同的目录中生成de_DE_ResourceModule.swf。

然后你再改变下-locale=zh_CN,生成zh_CN_ResourceModule.swf。

然后把这两个swf放到主程序相同目录下,测试加载即可。

Flex 国际化(flex Localize)的更多相关文章

  1. Maven下Flex国际化配置

    之前写了flashbulid.initellij下的flex国际化配置,它们都是在本地打包发布的,那么我们的工程用maven管理了,需要自动发布.这时候如何修改flex的pom文件,来让它build的 ...

  2. 【转】【Flex】FLEX 学习网站分享

    [转:http://hi.baidu.com/tanghecaiyu/item/d662fbd7f5fbe02c38f6f764 ] FLEX 学习网站分享 http://blog.minidx.co ...

  3. Flex 国际化(中英语言适配)

    原文地址:http://www.cnblogs.com/meteoric_cry/archive/2011/01/13/1934404.html(由于此贴时间久远,已做微调) 1.新建Flex Pro ...

  4. [flex布局]-flex教程

    简介:2009年,W3C提出了一种新的方案----Flex布局,可以简便.完整.响应式地实现各种页面布局.目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能. Flex布局是什 ...

  5. [flex 布局]——flex教程

    简介:2009年,W3C提出了一种新的方案----Flex布局,可以简便.完整.响应式地实现各种页面布局.目前,它已经得到了所有浏览器的支持,这意味着,现在就能很安全地使用这项功能. Flex布局是什 ...

  6. 伸缩容器-display:flex设置flex属性的理解

    1.flex属性 1.1 flex属性是flex-grow, flex-shrink 和 flex-basis的简写,默认值为0 1 auto. flex-grow: 定义项目的放大比例,默认为0,即 ...

  7. flex和flex:1的含义

    一.flex详解 flex可以参考阮一峰老师的flex布局教程,很详细看完啥都懂了 链接:http://www.ruanyifeng.com/blog/2015/07/flex-grammar.htm ...

  8. Fms3和Flex打造在线视频录制和回放

    本博推荐文章快速导航: Sql Server2005 Transact-SQL 新兵器学习MCAD学习 代码阅读总结 ASP.NET状态管理 DB(数据库)WAPWinFormFlex,Fms aie ...

  9. OpenCASCADE Expression Interpreter by Flex & Bison

    OpenCASCADE Expression Interpreter by Flex & Bison eryar@163.com Abstract. OpenCASCADE provide d ...

随机推荐

  1. Ubuntu修改密码长度太短或太简单解决

    在安装 Ubuntu 的时候建立的帐户 sai,想把密码改成两个字母aa,方便输入. 运行终端 sai@xmomx:~$ passwd sai更改 sai 的密码.(当前)UNIX 密码: xx输入新 ...

  2. http概述

    HTTP是一个属于应用层的面向对象的协议,由于其简捷.快速的方式,适用于分布式超媒体信息系统.它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展.目前在WWW中使用的是HTTP/1.0的第 ...

  3. iOS 进阶 第六天(0402)

    0402 通知和代理的区别 代理是一对一的,只能是调用实现了协议里的方法,对象作为实现了该方法才能执行方法 通知是多对多,它是通过通知中心分发 通知要及时移除,如果不及时移除可能会收到多次通知,就好像 ...

  4. Java中如何防止内存泄漏的发生

    在Java开发中我们常常会遇到内存泄漏的情况发生.那么为什么会发生内存泄漏,以及怎样去防止! 内存泄漏的定义:对象已经没有被应用程序使用,但是垃圾回收器没办法移除它们,因为还在被引用着. 为什么会发生 ...

  5. Backbone.Events—纯净MVC框架的双向绑定基石

    Backbone.Events-纯净MVC框架的双向绑定基石 为什么Backbone是纯净MVC? 在这个大前端时代,各路MV*框架如雨后春笋搬涌现出来,在infoQ上有一篇 12种JavaScrip ...

  6. 领接表的建立和它的DFS, BFS;;;

    //图的建立的实现->邻结矩阵和邻结表两种表示方法 #include <cstdio> #include <cstdlib> //#define _OJ_ int vis ...

  7. linux_fedora nexus_auto_start

      fedora20发布,不对rc.local支持,其实只是删除了rc.local文件,如果想在开机时能够运行自己写的脚本,只要新建rc.local文件就可以了,下面让我们来测试下吧: 环境:fedo ...

  8. 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。

    // ConsoleApplication2.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "stdafx.h ...

  9. POJ 3468 A Simple Problem with Integers(线段树区间更新,模板题,求区间和)

    #include <iostream> #include <stdio.h> #include <string.h> #define lson rt<< ...

  10. POJ3083Children of the Candy Corn

    题意:给你一个迷宫,入口处标为S,出口处标为E,可以走的地方为“.”,不可以走的地方为#,求左转优先时从出口到入口的路程,再求右转优先时,出口到入口的路程,最后求从出口到入口的最短路程. 思路:求前两 ...