原文 http://www.cnblogs.com/yangpigao/archive/2013/04/25/3043627.html
今天项目里要做国际化,在网上找了一下flex的国际化,不管外网,还是百度的文章,都是在flash builder环境下开发的,intellij基本没有这方面的资料,由于项目组都在用intellij,就研究了在intellij下的配置和实现。 下面是具体的实现。
1.目录结构:
2. flex compiler configuration,分别点击 en_US--sources,zh_CN--sources,把它们添加到Source Folders中
3.修改支持语言
4.添加本地化支持,在cmd 里运行 copylocale en_US zn_CN
5.实现方式如下,i18n.mxml
<?xml version="1.0"?> <!-- * Created with IntelliJ IDEA. * User: DongYang * Date: 13-4-25 * Time: 下午9:45 * Progress every day a little more --> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="creationCompleteHandler(event)" > <s:Button id="but" label="{resourceManager.getString('language','hello')}"/> <fx:Metadata> [ResourceBundle("language")] </fx:Metadata> <fx:Script><![CDATA[ import mx.events.FlexEvent; import mx.resources.ResourceManager; private function creationCompleteHandler(event:FlexEvent):void { //访问javascript 函数 getLanForBrowser,获取当前浏览器的语言环境。 var str:String = ExternalInterface.call("getLanForBrowser", "") as String; //兼容性处理 switch(str){ case "zh-CN": resourceManager.localeChain = ["zh_CN"]; break; case "en_US": resourceManager.localeChain = ["en_US"]; break; default: ResourceManager.getInstance().localeChain = ["zh_CN"]; break; } } ]]></fx:Script> </s:Application>
6.javascript 代码,把它写到 index.template.html 里以便 flex可以访问
function getLanForBrowser() { var language; if (navigator.language) { language = navigator.language; } else { language = navigator.browserLanguage; } return language; }