Yury Euceda
Yury Euceda

Reputation: 566

Better way to develop a multilingual application in Flex

I'm planning to create a multilingual app in Flex. My approach is kind of the following: To have an XML with all the phrases in application...

<mx:Script>
<![CDATA[
public var selectedLanguage : String = "spanish";
public var language : xml =
    <xml>
      <message id="<<hashcode of the string in english>>" english="hello world" spanish="hola mundo" french="bonjour tout le monde"/>
      <message id="<<hashcode of the string in english>>" english="good bye every body" spanish="adios a todos" french="tout le monde au revoir"/>
    </xml>;

//Then a function to make the translation:
public function translate(msg:String):String{
    //Maybe not a hashCodeFunction but some function to return an unique code for every string
    var hashcode : int = hashCodeFunction(msg);
    var translation : String = language.message.(@id==hashcode)[selectedLanguage];
    if(translation==null) return msg;
    return translation;
}
]]>
</mx:Script>

<mx:Button label="translate('hello world')"/>

Well, the xml could be structured in a different way but what I want is create all labels like "translate('some text')" because in this way I think is better at programmer time, and at the end of the development process just create a "pre processor" that is going to look for ALL strings in source code like "translate('some text')" and extract 'some text' then calculate the hash code and append it to xml, and when xml is ready all the application is going to be multilingual.

I want to know if someone has another approach to share.

Upvotes: 1

Views: 802

Answers (1)

Jason Sturges
Jason Sturges

Reputation: 15955

Adobe implements Resource Bundles for localization and internationalization of text and images.

Compiler options may be specified to include locales:

-locale=en_US,ja_JP,fr_FR

Then, locale specific properties may be retrieved such as:

<s:Label text="{resourceManager.getString('bundleName', 'key')}" />

References:

Upvotes: 3

Related Questions