I will explain how to create an multilingue application with RessourceBundle class. There is 3 steps to do multilingue application
Summary
- Create your properties files
- Create folders to insert properties files
- Change your flex compiler configuration to insert path to the properties files
- Insert some code lines in your application
Detail
1. Create your properties files
To translate your application you hate to create some properties files. In those files you have to insert you label or text message that you want to change in your app.
Exemple:
I created 2 files.
The first one is login_EN.properties.
Here what I put in the file…
pLoginTitle = Connection…
pLoginUsername = Username
pLoginPassword = Password
pLoginTitle is for the label title on the login window and …
The seconde one is login_FR.properties
Here what I put in the file…
pLoginTitle = Connexion…
pLoginUsername = Utilisateur
pLoginPassword = Mot de passe
2. Create folders to insert properties files
When you have created your properties files you hate to put it in a locales folder that you will create from your project folder.
Exemple:
[PROJECT]/locales/multi
and put your properties files in the foder
3. Change your flex compiler configuration to insert path to the properties files
Change your additional compiler arguments in your project properties configuration to “-locale en_US -sp ../locales/multi”
4. Insert some code lines in your application
In your flex code you have to use RessourceBunlde class used for localization.
Exemple:
import mx.resources.ResourceBundle;
ResourceBundle(”login_FR”)]
private var rb_fr:ResourceBundle;
[ResourceBundle("login_EN")]
private var rb_en:ResourceBundle;
private var langue:String;
[Bindable(event="langChange")]
private function geti18nText(key:String):String{
return this["rb_"+langue].getString(key);
}
private function ChangeLangue():void {
if (btnLangue.label == “English version”) {
this.langue = “en”;
btnLangue.label = “Version francaise”;
} else {
this.langue = “fr”;
btnLangue.label = “English version”;
}
var e:Event = new Event(”langChange”);
this.dispatchEvent(e);
}
I created a button in the design form and insert ChangeLangue() in the onclick event and you will get an multilinge application with flex. I showed you a very simple exemple of what you can do.