Flex国际化I18NMakeYouFlexProInternationalization沪江网-尹星军Flex使用.properties文件实现国际化,环境配置•在Flex中默认只支持en_US,ja_JP这两种本地化(D:\ProgramFiles\Adobe\FlexBuilder3\sdks\3.2.0\frameworks\locale)•添加新的本地化支持-sdk的bin目录下,运行命令:copylocaleen_USzh_CN(需安装javaruntime)•默认的语言资源文件D:\ProgramFiles\Adobe\FlexBuilder3\sdks\3.2.0\frameworks\projects\framework\bundles本地化编译-编译不同的语言版本•创建项目的语言资源文件1)多语言包目录-copylocaleoriginal_localenew_locale2)资源文件(.properties)•配置语言包-locale=en_US1)sourcepath+=e:\resource\locale\{locale}2)添加sourcepath3)SDK的默认语言包资源使用.properties文件实现国际化•interface.properties。Key=value(utf-8键-值)pic=Embed(“demo.gif)swf=Embed(“demo.swf)•resourceManager•[ResourceBundle]元数据标签绑定mx:Metadata[ResourceBundle(“interface)]/mx:Metadata本地化资源中使用绑定•@Resource指令mx:Labeltext=“@Resource(key=‘key’,bundle=‘interface’)”/•AS代码绑定[Bindable]privatevar_as:String;_as=resourceManager.getString(interface',‘key');运行时改变资源包•绑定mx:Texttext={resourceManager.getString('source','user.name')}“•编译参数localeen_USzh_CN•改变语言资源resourceManager.localeChain=[locale];//en_USzh_CNResourceManager调度changeUICompoment.resourceChange()SDK语言资源Framework_rb.swc•\sdks\3.2.0\frameworks\projects\framework\bundles\en_US\src•sdks\3.2.0\frameworks\locale•compc编译语言包compc-locale=zh_CN-source-path=..\frameworks\projects\framework\bundles\zh_CN\src-include-resource-bundles=collections,containers,controls,core,effects,formatters,logging,SharedResources,skins,states,styles,validators-output=..\frameworks/locale/zh_CN/framework_rb.swc资源模块化•命令行编译指定资源•mxmlc-locale=en_US-source-path=locale/{locale}//相对于FLEX的目录,使用绝对路径-include-resource-bundles=interface,interface1-outputen_US_ResourceModule.swf•mxmlc-locale=zh_CN-source-path=locale/{locale}-include-resource-bundles=interface,interface1-outputzh_CN_ResourceModule.swf加载资源•ResourceManager的loadResourceModule()//异步•vareventDispatcher:IEventDispatcher=resourceManager.loadResourceModule(resourceModuleURL);•UIComponent类resourcesChanged()本地化字体•mx:Style•@font-face{src:url(“en.ttf);fontFamily:enFont;}•@font-face{src:url(“jp.ttf);fontFamily:jpFont;}•.enFont{•fontFamily:enFont;•}•.jpFont{•fontFamily:jpFont;•}•/mx:Style#/locale/en_US/Font.propertiesfonsty=ENFont#/locale/ja_JP/Font.propertiesfontsty=JPFontmx:TextstyleName={resourceManager.getString('Font',‘fontsty')}/FLASHIDE动态嵌入字体–字型建立fontlib.swf运行库共享导出继承font类名fontlib–动态调用fontlib.swf运行库共享导入继承font类名fontlib–问题:无法同时兼容中日字符–发现字符实际存在,但无法显示,未得到渲染FLEXIDE–建立AS工程flexFont(主类)•[Embed(source=C:/WINDOWS/Fonts/verdana.TTF,fontName=“verdana,mimeType=application/x-font)]••publicvartestFont:Class;•/////////////////////////////////•\Adobe\FlexBuilder3\sdks\3.2.0\frameworks\flash-unicode-table.xml•unicodeRange=‘U+0020-U+002F”标记可以标记字符嵌入范围引用本地字体varfontLibrary:Class=event.target.applicationDomain.getDefinition(embedFont_localFont)asClass;trace(fontLibrary);Font.registerFont(fontLibrary);}functiontest(){var_embeddedFonts:Array=newArray();_embeddedFonts=Font.enumerateFonts(false);trace(_embeddedFonts);trace((_embeddedFonts[0])实际应用1)渲染标准组件字体(Label的public属性textField:TextField进行设置)•c.textField.embedFonts=true;•c.textField.setTextFormat(tf);•c.textField.x=10;•c.textField.width=160;•c.textField.height=40;2)渲染动态/输入文本框:•vartx:TextField=newTextField();tx.type=input;//自行改正tx.embedFonts=true;vartxt:TextFormat=newTextFormat(_embeddedFonts[0].fontName,20,0xFF0000);;txt.size=28;StyleManager.setStyle(textFormat,txt);谢谢大家不周之处,请多包含