Skip to main content
Inspiring
March 6, 2013
Question

Localization not working as expected

  • March 6, 2013
  • 2 replies
  • 9007 views

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:

  1. adding resources.properties in ./locale/en_US and ./locale/de_DE with one key 'test' and a translated string in it
  2. adding the folder 'locale/{locale}' in ActionScript Build Path -> Source Path
  3. adding '-locale=de_DE,en_US' in ActionScript Compiler as an additional compiler argument
  4. in source code i add the following ResourceBundle metadata:

          [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!

This topic has been closed for replies.

2 replies

Participating Frequently
January 19, 2014

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,

kkm19
Participant
February 9, 2015

I also have a problem with it. I believe

  <fx:Metadata>

    [ResourceBundle("bundle")]

  </fx:Metadata>

isnt support yet?

valley tAuthor
Inspiring
March 7, 2013

Meanwhile i gave up ResourceManager and ResoureBundle and wrote my own solution.

Inspiring
March 8, 2013

Can you tell us your solution?

valley tAuthor
Inspiring
March 9, 2013

Sure:

  1. adding the key/value pairs in /locales/resources.xy_AB.txt files and adding the locales directory as a source directory (locales directory is outside the source folder)
  2. againg using LocaleUtil.sortLanguagesByPreference function to determine the list of most suitable languages
  3. i wrote a new class LocalesManager with a function initData(locale:String, resource:String, format:String = "txt"):void, which  can be called various times for different resources, where the function loads the correct file, parses it and stores the found key/value pairs in a Dictionary, which itself will be stored in a Dictionary that handles the resources
  4. after every successful initData call the function dispatches an Event that the loading is finished
  5. to receive a localized string i wrote another  function getString(resource:String, key:String):String

That's it. When switching the language on my mobile device i get the strings back for the new language.