Copy link to clipboard
Copied
public static loadStringEx(stringID: String, languageCode: String) : String
This is the loadStringEX declaration, and it would seem to indicate that it's a multidimensional array? that is, the Locale.stringIDArray. (Or it's an object)
var arr:Array = Locale.stringIDArray;
for (var i=0; i<arr.length; i++) {
IDLabel = Locale.loadStringEx(Locale.stringIDArray, loc)
ID = Locale.stringIDArray;
trace("ID :" + ID + " is " + IDLabel);
trace("Array ID:"+ Locale.stringIDArray + ":" + IDLabel);
}
and this returns
ID :IDS_008 is 复位
Array ID:IDS_008:复位
ID :IDS_010 is 目前的地理定位数据\n
Array ID:IDS_010:目前的地理定位数据\n
ID :IDS_015 is 水平精度
I am thinking of extracting this data, easy enough in this instance, and putting it into an SQLite database. That way I can recall it anytime anywhere to use in various parts of the program.
I can't find anyone doing Locale work and the examples in the Adobe help are just too basic. The ID and the Label have to be available to me from anywhere in the program.
You're welcome and if you're all set please mark a correct answer to mark the thread answered so we can filter unanswered questions. Keep at it and good luck!
Copy link to clipboard
Copied
For some reason you must really hate the API Reference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/lang/Locale.html#stringIDArray
What has it done to you to deserve this cruel fate?
Copy link to clipboard
Copied
well, yes. Been strugglling with this for a week now. I will have to look at other options. SQL may work, as there are only 24 strings to store. Well, with SQL maybe more, because that will also allow me to store whole paragraphs as well. could be handy.
Anyway, the program is 1660 lines long so far and growing. and that's just the main class.
The only way I can get someting into this btnAddress.label is from WITHIN the 'function localeCallback(success:Boolean):void { ....'
btnAddress.label = Locale.loadString("IDS_001");
}
}
whence it has just loaded the xml file. As in the sample in that AS3 Flash page.
I can list the IDS_xxx and the strings that go with them - but ONLY from within that localeCallBack function.
I'm beginning to think I'm the only person stupid enough to try Localeizing their project. There are lots of similar examples out there, just copies of the AS3 ones. I can find no working projects that use Locale. Maybe someone else can.
Do I hate it? No, of course not. I love trying to solve the problems - so much so that I'm awefully tempted to switch to XCode. Good old C.
Copy link to clipboard
Copied
c would be an upgrade, I vehemently hate objective-c. The sheer verbosity and back in the day the triple requirement (between .h/.c) to declare/synthesize variables, ugh what an outdated mess. (NULL, NIL? Sometimes used in the same method? ....).
Anyhow I do TONS of localizations. They usually don't co-exist in the same project. When they do I use embedded TTFs in SWCs via Flash Builder while using XML for the actual data and haven't had any issue since then.
I think we already had this conversation but overall the Strings panel never saved me time, just gave me obstacles, so I always used my own well formed XML data file for ease.
Copy link to clipboard
Copied
the Strings panel never saved me time, just gave me obstacles, so I always used my own well formed XML data file for ease.
Totally agree with this.
I think Adobe introduced it with Flash 8 and it was painfully to use it even with AS2.
Now when you have a easy way of manipulating XML in AS3 its just not worth the trouble.
Copy link to clipboard
Copied
I only use it for interface text when I have minimal text. Simple things like "Play", "Pause", "Loading..".. Otherwise it's more of a designer solution which Adobe always takes the time to provide, but I don't feel the OP is in need of that level of simplicity and it's actually interfering with advanced needs.
Copy link to clipboard
Copied
I admit, I have become somewhat obsessed with using the Locale.xxxxx things, that I totally - I mean TOTALLY overlooked the fact that underneath all that Strings panel stuff, and the built in Locale libraries - is plain old XML files. Therein is the data - IDS_XXX - 'Hello World" etc etc labels.
HA.! In the end - I have to build the xml files anyway, although I admit the Panel is a reasonably neat interface for that, once I have the XML file, I can pretty much do what I like with that.
Talk about forests and trees.
ok. Starting again....
Thanks for the help from both of you. The Locale. stuff almost works, but just not well enough. not for me anyway, and it sounds like I"m not alone.
Copy link to clipboard
Copied
The Locale documentation helps! It has methods such as addXMLPath, loadLanguageXML and the description stating:
The Flash Strings panel allows you to use string IDs instead of string literals in dynamic text fields. This allows you to create a SWF file that displays text loaded from a language-specific XML file.
Yes, it just automates (for designers) creating the XML files. There's no magic, just a little automation if you really don't want to learn scripting. Learning is always better .
Glad you've found your path. If you're all set please mark correct/helpful replies so we can filter out unanswered questions to attend. Good luck!
Copy link to clipboard
Copied
One last question.
In the strings panel, settings. The top option is to populate at automatically at runtime, not using as3,
How does this work because every example i can find is using actionsceipt?
Copy link to clipboard
Copied
Choose "automatically at runtime" so the SWF auto-detects the users language and replaces all strings based on the replacements you provide for that language with the stringID you assign to any TextField. Otherwise you can "bake" in the text using "manually using stage language" which will actually change the strings once during compile time to the language of the machine the SWF is compiling on and then never again (no matter the langauge of the user). Lastly if you want to control it all yourself then use "via ActionScript at runtime".
These are explained in the unordered list descriptions on this page:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/lang/Locale.html
Copy link to clipboard
Copied
Yes, it's this one.
Choose "automatically at runtime" so the SWF auto-detects the users language and replaces all strings based on the replacements you provide for that language with the stringID you assign to any TextField
Can you make this work? Is there a working example, because this does nothing. More over - I am wondering at the last line, does this mean that the language file is loaded each and every time it's referenced? Even if it's loaded at run time . that statement seems to indicate that it's not loaded until the last thing to be done?
In any event, I can not get this to display anything. anywhere.
var greeting_txt:TextField = new TextField();
greeting_txt.x = 40;
greeting_txt.y = 40;
greeting_txt.width = 200;
greeting_txt.height = 20;
greeting_txt.autoSize = TextFieldAutoSize.LEFT;
Locale.autoReplace = true;
Locale.addDelayedInstance(greeting_txt, "IDS_GREETING");
Locale.loadLanguageXML("en");
Copy link to clipboard
Copied
How about adding greeting_txt to a display list? This is basic.
Add in:
addChild(greeting_txt);
Or obviously it will not be displayed until it's added to the display.
Copy link to clipboard
Copied
Ok, I missed that one. Mea culpa. Not to worry, the saga continues.
This one works ......
tiAddress = new TextInput();
tiAddress.textField.background = true;
tiAddress.textField.backgroundColor = 0x7AB900;
tiAddress.x = 10;
tiAddress.y = 10;
tiAddress.height = 20;
tiAddress.textField.multiline = true;
tiAddress.textField.wordWrap = true;
tiAddress.width = stage.stageWidth - 20;
// IDS_002
//tiAddress.text = "Address, City, State, Zip or Latitude,Longitude";
Locale.addDelayedInstance(tiAddress, "IDS_002");
//tiAddress.text = "IDS_002";
tiAddress.setStyle("textFormat", format);
tiAddress.addEventListener(MouseEvent.CLICK, tiAddressClickHandler);
addChild(tiAddress);
This one doesn't ....
btnTwitterUserNP = new Button();
btnTwitterUserNP.width = stage.stageWidth - 150;
btnTwitterUserNP.height = 25;
btnTwitterUserNP.x = 10;
btnTwitterUserNP.alpha = 0.9;
Locale.autoReplace = true;
Locale.addDelayedInstance(btnTwitterUserNP, "IDS_006");
//btnTwitterUserNP.label = "IDS_006";
// IDS_006
//btnTwitterUserNP.label = "Tweet This Location";
btnTwitterUserNP.setStyle("textFormat", btnFormat);
btnTwitterUserNP.y = stage.stageHeight - 70;
btnTwitterUserNP.addEventListener(MouseEvent.CLICK, btnTwitterUserNPMouseClickHandler);
addChild(btnTwitterUserNP);
This last one either produces [Label] in the Button, or if I uncomment the btnUserNP.label line, it puts "IDS_006" into the button?
So now I can set up the TextFields - but not the buttons .... any ideas?
Thanks guys. Sorry.
Copy link to clipboard
Copied
Parameters
instance:Object — Instance name of the text field to populate
Docs tend to be as accurate as possible so it's easy to overlook something. It doesn't specify it can intelligently detect the class of the object. Because custom or customized components can be used it wouldn't want to get into the hassle of trying to figure out where text is located if the standard Button component isn't used (my guess). So it only supports TextFields.
You'll just have to use the loadStringEx for anything you need to set a custom property for:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/lang/Locale.html#loadStringEx()
e.g. English:
btnTwitterUserNP.label = Locale.loadStringEx("IDS_006","en");
All that's left is determining the current location string (e.g. flash.system.Capabilities.language.substr(0, 2);).
Copy link to clipboard
Copied
Hi there.
Thanks, that got me going in the right direction, and along with just about everythhing I've studied this last week and a half ... I think I have a working model. Pretty much anyway.
The result:
These are only screen shots of course, but it is working the way I want it.
I had to change your suggestion slightly, to this
ClearWebView.label = Locale.loadString("IDS_018");
and build the whole callback thing around it - I'll keep working on it, as it's a bit clunky as it is, but hey it works ...
private function createClearWebViewButton():void
{
var ClearWebViewFormat:TextFormat = new TextFormat("Verdana",12);
ClearWebViewFormat.color = 0x254117;
ClearWebViewFormat.bold = true;
ClearWebViewFormat.italic = true;
ClearWebView = new Button();
ClearWebView.width = stage.stageWidth - 188;
ClearWebView.height = 20;
ClearWebView.x = 100;
ClearWebView.y = stage.stageHeight - 21;
ClearWebView.alpha = 0.9;
//ClearWebView.label = "Close Window";
Locale.setLoadCallback(Callback);
Locale.addXMLPath(loc, loc + "/PinPointPremium_" + loc + ".xml");
Locale.loadLanguageXML(loc);
function Callback(success:Boolean):void {
ClearWebView.label = Locale.loadString("IDS_018");
}
ClearWebView.setStyle("textFormat", ClearWebViewFormat);
ClearWebView.addEventListener(MouseEvent.CLICK, handleClearWebViewButton);
addChild(ClearWebView);
}
In other parts of the program, I can actually load a lot of the labels at once, as I did originally. I have also switched back to the Strings option of "using ActionScript Control".
This is the set of text label controls from just inside the main function (Constructor position) that does most of the labels, so I only have to run the other bit in about 4 or 5 places just to get some bits in that don't get seen until other user actions.
This bit also allows me to set the language I'm testing in, so I can make everything fit.
loc = Capabilities.language;
//trace("The default language: " + loc);
// for testing purposes, set it to what language you want
loc = "de";
//trace("The new language: " + loc);
// load the language files
Locale.addXMLPath(loc, loc + "/PinPointPremium_" + loc + ".xml");
Locale.loadLanguageXML(loc);
Locale.setLoadCallback(localeCallback);
Locale.addXMLPath(loc, loc + "/PinPointPremium_" + loc + ".xml");
Locale.loadLanguageXML(loc);
var arr:Array = Locale.stringIDArray;
function localeCallback(success:Boolean):void {
//{
//for (var i=0; i<arr.length; i++)
//IDLabel = Locale.loadStringEx(Locale.stringIDArray, loc)
//ID = Locale.stringIDArray;
//}
//trace(IDs.describe());
//btnAddress.label = "PinPoint the Entered Address"
btnAddress.label = Locale.loadString("IDS_001");
//tiAddress.text = "Address, City, State, Zip or Latitude,Longitude";
tiAddress.text = Locale.loadString("IDS_002");
//btnInfo1.label = "Altitude";
btnInfo1.label = Locale.loadString("IDS_003");
// btnInfo2.label = "Speed";
btnInfo2.label = Locale.loadString("IDS_004");
// btnDirection.label = "Direction";
btnDirection.label = Locale.loadString("IDS_005");
//btnTwitterUserNP.label = "Tweet This Location";
btnTwitterUserNP.label = Locale.loadString("IDS_006");
//btnGPS.label = "PinPoint My Current Location";
btnGPS.label = Locale.loadString("IDS_007");
//btnReset.label = "r";
btnReset.label = Locale.loadString("IDS_008");
//btnInfo.label = "i";
btnInfo.label = Locale.loadString("IDS_009");
//tfInfo.text = "Current Geolocation Data:\n";
tfInfo.text = Locale.loadString("IDS_010");
//ClearWebView.label = "Close Window";
//ClearWebView.label = Locale.loadString("IDS_018");
//IDLabel = Locale.loadString("IDS_018");
}
But however - many thanks for your patience and your help. It is most appreciated, and even where I was beginning to think I was as thick as a plank.... I kept at it. So its almost working.... thanks again.
Copy link to clipboard
Copied
You're welcome and if you're all set please mark a correct answer to mark the thread answered so we can filter unanswered questions. Keep at it and good luck!
Copy link to clipboard
Copied
OP is asking what loadStringEx is, not stringIDArray which self-describes itself.
The documentation does not mention how the loadStringEx() static method holds data. It could be an Object, Dictionary or Array. In any case a string comparison is needed so the lookup will be slow regardless what it is if there's a ton of strings converted to multiple languages.
I don't feel a SQLLite DB will perform any better with a string based query either but may be easier to manage complex joins of multiple languages and other things the Locale class does not do by default.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now