HowTo Localize Flex Applications

Aus JSUG

Wechseln zu: Navigation, Suche

Inhaltsverzeichnis

[Bearbeiten] Procedure

[Bearbeiten] Copy framework locale

This has to be done only once for each new locale:

cd /path/to/flexbuilder/
cd sdks/3.x.x
bin/copylocale en_US de_AT


[Bearbeiten] Create localized resources

Projectstructure

Create the folder projectName/locale/en_US and projectName/locale/de_AT and put a file called in mystuff.properties both folders.

de_AT/mystuff.properties:

hello=Derre, {0}!

en_US/mystuff.properties:

hello=Hello, {0}!

[Bearbeiten] Change compiler arguments

Go to: Project Properties / Flex Compiler / Additional compiler arguments and change the value to:

-locale=en_US,de_AT


[Bearbeiten] Add source path

Go to: Project Properties / Flex Build Path / Add Folder ... and enter the value:

locale/{locale}


[Bearbeiten] Use ResourceManager

<?xml version="1.0" encoding="utf-8"?>
<mx:Application layout="vertical"  xmlns:mx="http://www.adobe.com/2006/mxml">
 
    <mx:Metadata>
        [ResourceBundle("mystuff")]
    </mx:Metadata>
 
    <mx:Script>
        <![CDATA[
            [Bindable]
            private var availableLocales: Array = [ "en_US", "de_AT" ];
 
            [Bindable]
            private var username: String = "Harald";
 
            private function onLocalesComboChange(): void {
                this.resourceManager.localeChain = [this.localesCombo.selectedItem];
            }
        ]]>
    </mx:Script>
 
    <mx:ComboBox id="localesCombo" dataProvider="{availableLocales}" change="this.onLocalesComboChange()" />
 
    <mx:Label text="{this.resourceManager.getString('mystuff', 'hello', [this.username])}" />
 
</mx:Application>

[Bearbeiten] Appendix

[Bearbeiten] Notes

You also can define non-String values:

flag=Embed("assets/flags/austria.gif")
SORTER=ClassReference("sortingClasses.de_AT.Sorter")


Written by Christoph Pickl.

[Bearbeiten] Links

Persönliche Werkzeuge