Best Practices for Internationalizing a Flex Appli

2020-05-24 06:11发布

问题:

I am looking into internationalizing a Flex application I am working on and I am curious if there are any best practices or recommendations for doing so.

Googling for such information results in a handful of small articles and blog posts, each about doing it differently, and the advantages and disadvantages are not exactly clear.

Edited to narrow scope:

  • Need to support only two languages (en_CA and fr_CA)
  • Need to be able to switch at runtime

回答1:

Of course, after googling a bit more I come across an article on runtime localization.

And followed these steps:

Add the following to the compiler arguments to specify the supported locales and their path: (In Flex Builder, select project and go properties -> Flex Compiler -> Additional Compiler Arguments)

-locale=en_CA,fr_CA -source-path=locale/{locale}

Create the following files:

src/locale/en_CA/resources.properties
src/locale/fr_CA/resources.properties

And then the compiler complains: unable to open 'C:\Program Files\Adobe\Flex Builder 3\sdks\3.1.0\frameworks\locale\en_CA'

Which looks to be related to bug SDK-12507

Work around:
In the sdks\3.1.0\bin directory, execute the following commands:

copylocale en_US en_CA  
copylocale en_US fr_CA

This will create the locale directories in the Flex Builder installation and build some required resources into them.

Then in your .mxml files, reference the resource bundle:

<mx:Metadata>
    [ResourceBundle("resources")]
</mx:Metadata>

And internationalize the strings:

<mx:TitleWindow title="Window Title">

becomes:

<mx:TitleWindow 
    title="{resourceManager.getString('resources', 'windowTitle')}">

and

var name:String = "Name";

becomes:

var name:String = resourceManager.getString("resources", "name");

And in your src/locale/en_CA/resources.properties file:

windowTitle=Window Title
name=Name