The story of multilanguage support of your application
or localization in Flash begins with Strings Panel that can be accessed Window->Other Panels->Strings. Actually the basic logic of localization is creating of file (txt, XML, database, SWF(in Flex) or other), containing key-value pairs (ID of the string as key and value actual string) for each language.
When you choose Settings from String Panel you can add languages from the list on

right that your application would support or custom languages (mk (Macedonian)) and Flash will crate the xml language files for you in separate folder. (This is very buggy and you will find sometime new version of your xmls where the 0S folder pointer was pointing last time)
There are 3 ways how you can use those files:
"automatically at runtime" —Flash Player replaces string IDs with strings from the XML file matching the default system language code returned by flash.system.capabilities.language.
"manually using stage language" —String IDs are replaced by strings at compile time and cannot be changed by Flash Player.
"via ActionScript at runtime" —String ID replacement is controlled using ActionScript at runtime. This option gives you control over both the timing and language of string ID replacement.
I prefer the last, cos give me more flexibility then other two . TIP:If you use it be sure that you not have static fields. You will got stuck with static fields for in scenario when you want to change application languages in runtime.

Creating key(ID)-value pairs is done by selecting of the TextField and filing the data in StringsPanel. The smaller TextField in Strings Panel is for ID and the bigger one is for string value for currently selected language. When you hit Apply, you will see that row in the table below got filled and you can add string values for additional languages.
XML created would look like

TIP:It would be of great help to the translator and developer if you put descriptive IDS like IDS_CREATBUTTON_LABEL, IDS_BASEWND_CAPTION and so on
As I said above for bigger control and flexibility you will use "third" mode and you will create the XML files yourself, without using Strings Panel at all, following the requested convention.
In Flash ResourceManager(FlexSDK) class is Locale class import fl.lang.Locale; and have handy methods.
In the constructor of your application you can set the location from where swf will load xml file for requested language designated with language code (ex. "en","mk"):
Locale.addXMLPath("mk", pathT0+"My_mk.xml"); Locale.addXMLPath("en", pathT0+"My_en.xml");You can load different languages in runtime:
btn.addEventListener(MouseEvent.Click,onSwitchButtonClick); private function onSwitchButtonClick(e:MouseEvent):void { //initiate loading of the xml file previously added with addXMLPath Locale.loadLanguageXML(languageCode,onLanguageLoad); } private function onLanguageLoad(success:Boolean):void { //setLanguage(languageCode:String):void function used to change language of all components of the window or group or components that need language change. setLanguage(languageCode); } public function setLanguage(languageCode:String):void { myTextField.text = Locale.loadStringEx("IDS_TEST_STRING", languageCode); myCheckBox.label =Locale.loadStringEx("IDS_MYCHECKBOX_LABEL", languageCode); }In the case of localization of the components that have dataProvider like ComboBox,List,TabBar,Tree... we can use JSON library to decode: //in language xml file < resname="IDS_COMBOBOX_DATA">
myComboBox=new DataProvider(JSON.decode(Locale.loadStringEx("IDS_COMBOBOX_DATA" ,languageCode ) as Array);StringUtil is used to fill special tags %d,%s... with variables values //inside you language xml file < resname="IDS_STRING_WITH_FORMATING" >
StringUtil.format(Locale.loadStringEx("IDS_STRING_WITH_FORMATING", languageCode),"'"+stringVariable1+"'",intVariable2);
Source:download Tweets by @Winx_Alex
Very good topic, the better I liked about String panel and multilingual.
ReplyDeletePlease help me, I'm trying to make a flash site with two languages and do not really understand the explanation of how to call the xml to change the language with a button.
Do you have any ready example?
I thank you'm new to as3 but I understand a bit about the classes.
Sincerely João Mello.
thx bro :)
ReplyDeleteok please combobox change to language ?
ReplyDelete@Mr.Salsero
ReplyDeletedeclare
Locale.addXMLPath("mk", pathT0+"My_mk.xml");
Locale.addXMLPath("en", pathT0+"My_en.xml");
add combobox instead of Button with list of language codes("mk","en"... you want to switch
and addListener(Event.Change,onSwitchButtonClick)
inside
function onSwitchButtonClick(e:Event){
Locale.loadLanguageXML(e.target.selectedItem,onLanguageLoad);
}
Excellent, thanks a lot!.
ReplyDeleteFor those who work on l10n projects, I suggest to have a look at https://poeditor.com/, a translation management platform that can help you better manage your translation projects. Maybe it's worth giving a try.
ReplyDelete