Copy link to clipboard
Copied
Hi there,
i'm struggling with an AIR 3.6 mobile app that should support several languages (for testing 'de_DE' and 'en_US').
Here is what i do in Flash Builder 4.7:
[ResourceBundle("resources")]
public class Root extends Sprite
5. as a test i use the following code:
var sortedLocales:Array = LocaleUtil.sortLanguagesByPreference(["de_DE", "en_US"], Capabilities.languages, "de_DE");
ResourceManager.getInstance().localeChain = sortedLocales;
trace("String is: ", ResourceManager.getInstance().getString("resources", "test"));
When switching the language on my iPhone 4 from English to German i would expect that the trace shows the German string, but it's always the English one.
Also when i try to force the German language with
ResourceManager.getInstance().localeChain = ["de_DE"];
it shows the English string.
Capabilities.languages shows me that German is supported and when selected it's on 1st place in the list.
I also tried with languages "de" and "en" -> no change
When i check the packaged files for e.g. iOS i see that my 2 resources.properties files are not included and whatever i try they never get into the package.
What is missing here or is there a misunderstanding in how the language is chosen ?
Thank you for your help!
Copy link to clipboard
Copied
Meanwhile i gave up ResourceManager and ResoureBundle and wrote my own solution.
Copy link to clipboard
Copied
Can you tell us your solution?
Copy link to clipboard
Copied
Sure:
That's it. When switching the language on my mobile device i get the strings back for the new language.
Copy link to clipboard
Copied
Hi there
I'm having exactly the same problem here (AIR 3.6, Flash Builder 4.7). But somehow I don't really feel comfortable to write my own LocalizationManager when there's a built-in solution around. So I'm still trying to find the problem.
Anyone with similar experiences?
I'm grateful for any hint!
Copy link to clipboard
Copied
Since i use my own locales handler now i didn't investigate that problem further.
You describe exactly the same points i struggled with and couldn't solve. With the new solution i have seen that the .properties files still were not added to the build, therefore i changed them to .txt files.
Perhaps you could try that for your project.
If that doesn't help i can only encourage you to create your own LocalizationManager class. It took me 1h to write it and works without problems since then.
Copy link to clipboard
Copied
Thanks, valley t!
I'm definitely close to build my own localization solution based on your proposal!
As far as I understand, it is expected behaviour that the .properties files do not get packed into the build as their content is compiled into the app with [ResourceBundle("resources")]. This would also explain why the compiled app is slightly smaller in filesize when compiled without the -locale parameter. It looks like it is not neccessary to add the directories "locale/{locale}" into the package (in Properties > ActionScript Build Path > Source Path). That's how I understand the documentation:
When your application starts, the ResourceManager is automatically populated with whatever resource bundles were compiled into the application. If you create a code module, by default the resources that its classes need are compiled into the module. When the module is loaded into an application, any bundles that the application does not already have are added to the ResourceManager.
Btw.: I made a localization test with Flex 4.6, where everything worked as expected.
Copy link to clipboard
Copied
Ok… I finally took care of this issue and ended up – guess what – writing my own solution. It's very basic but that's all I need for the moment. And hey: It's working!
As it looks like we're not the only ones facing this issue it seems practical to share the code:
https://github.com/rekomat/AS3-LocaleManager
Note: The code has not been proven in production yet. Improvements welcome!
Copy link to clipboard
Copied
Cool!
From what i see we have more or less the same solution now 😉
Copy link to clipboard
Copied
That's good news!
I'm not really sure about the parsing part. I currently use String.split() twice: First to break the file contents into single lines and then to break the lines into key/value-pairs. After that, whitespace is cleaned using StringUtil.trim() (lines 242 - 261). Maybe this could be optimized for efficiency.
Do you have a better solution for parsing? Would be great if you would let me know!
Happy coding!
Copy link to clipboard
Copied
Actually it's pretty much the same in my code:
// first split for line breaks
var lines:Array = data.split("\n");
// now iterate over each line and populate the dictionary
var key:String;
var value:String;
var tokens:Array;
var line:String;
for (var i:int = 0; i < lines.length; i++) {
line = lines;
if (line == null || line.length == 0 || line.charAt(0) == "#" || line.charAt(0) == "!")
continue;
tokens = line.split("=");
if (tokens.length == 2) {
key = tokens[0];
value = tokens[1];
if (!dict.hasOwnProperty(key)) {
dict[key] = value;
} else {
throw new IllegalOperationError("Duplicate insert found for key " + key);
}
} else {
throw new IllegalOperationError("Error with line " + lines + ": More than 2 tokens found");
}
}
resources[resource] = dict;
dispatchEvent(new Event(LOCALE_RESOURCE_LOADED));
Cheers.
valley
Copy link to clipboard
Copied
Thanks for posting, valley!
Looks like we're coding in-sync.
Happy weekend (almost there)!
Copy link to clipboard
Copied
Thank you. Same to you.
Do you also live in Switzerland ?
Copy link to clipboard
Copied
Yep! I'll send you a PM shortly…
Copy link to clipboard
Copied
Probem happened in AIR3.5 change to AIR3.6 and is present in AIR 4.0.
Here is what I have.
I'm building with ANT script
<mxmlc
file="Main.as"
output="bin"
link-report="link-report.xml"
locale="en_US,da_DK,de_DE,nl_NL,sv_SE,nb_NO,pl_PL,fr_FR,fi_FI,en_GB,tr_TR,es_ES"
allow-source-path-overlap="true"
>
and then latter in the antscript
<source-path path-element="${PROJECT}/src/locale/{locale}"/>
And then in the code
[ResourceBundle("myResources")]
public class LocalesManager {
...
}
Works as expecte in AIR 3.5, but by simply changing SDK to 3.6 or any higher
compile fails with
Error: Unable to resolve resource bundle 'myResources'
[mxmlc] [ResourceBundle("myResources")]
[mxmlc] ^
[mxmlc]
[mxmlc] command line
[mxmlc] Warning: 'compiler.locale' is not fully supported.
Is it because compiler.locale is not fully supported? Confused,
Copy link to clipboard
Copied
I also have a problem with it. I believe
<fx:Metadata>
[ResourceBundle("bundle")]
</fx:Metadata>
isnt support yet?