How to make a Json in french and a json in english like a string resource.

Hi

I use a json data resource for english and one for french

In french

["Calme", "Très légère brise","Légère brise","Petite brise","Jolie brise","Bonne brise","Vent frais","Grand frais","Coup de vent","Fort coup de vent","Tempête","Violente tempête","Ouragan"]

and in english

["Calm", "Light air","Ligth breeze","Gentle breeze","Moderate breeze","Fresh breeze","Stronge breeze","Moderate gale","Fresh gale","Moderate gale","Severe gale","Whole gale","Moderate gale","Violent storm","Hurricane force"]

Each json is in default and in french directory

But when I cant use french or english when I change language.

It's in french even when I select english language.

Is it a bug and no option to use differents json ?

   <jsonData id="ArrayBeaufort" filename="Beaufort.json" />

Thanks

  • I'm not 100% sure, because I don't use jsons, but with strings.xml this works:

    There is a bug in simulator and Garmin Express that you can't choose the default language. The workaround i found is to add "eng" as a language in the manifest AND to add at least 1 string in resources-eng/. This way you can choose English in the settings editor.

  • I wonder if it works that way. 

    With a list that small, you could use string resources, which is known to work. 

  • no, jsons aren't translate like properties

    but of course  it's possible to do it but you have to use some tricks

  • Yes of course, but you have only 256 ressources available and sometimes it's too little

  • Maybe use sub strings. Put them together separated by some delimiter. 

    (If your issue was running out of resources, you should have mentioned that. Don’t have people try to guess what your real problem is.)

  • I have a same problem, and the problem is still here after 3 years.

    The default resources is english and I put the translated json into the resources-hun. I always get back the hungarian version for every language.

  • Yeah I think it's by design. I think the language-specific resource folder qualifiers only apply to string resources, and not other resource types.

    So if you have multiple instances of a non-language resource type under resource folders which are only differentiated by language, only one instance will ever be available.

    e.g. If I put different versions of a bitmap with the same resource ID (e.g. my_awesome_bitmap) under resources/, resources-fre/, and resources-deu/, only one version of the bitmap will ever be available, regardless of the selected language.

    As dpawlyk suggested, one workaround could be to put your data in a big string with a delimiter. e.g. change each JSON resource to a long string with data separated by semicolons (or whatever). Ofc this may lead to increased memory usage (peak and typical) due to the code and temporary memory used to decode these strings.

  • My solution is: make the JSON first level the language id.

    The "0" is the default the "8389360" is the Hungarian. Like this:
    <jsonData id="directionText">{"0": ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"], "8389360": ["É", "ÉK", "K", "DK", "D", "DNY", "NY", "ÉNY", "É"]}</jsonData>
    var _lang = System.getDeviceSettings().systemLanguage;
    var _directionTexts = WatchUi.loadResource( Rez.JsonData.directionText ) as Array;
    if (_directionTexts[_lang.toString()]) {
      _directionTexts = _directionTexts[_lang.toString()];
    } else {
      _directionTexts = _directionTexts["0"];
    }
    (sorry, I got error when I try format the text)
  • This isn't a bad solution, except for the possible increase in peak memory usage due to the larger JSON resource(s).

    e.g. say you have json data that would normally be 10K, such that when it's loaded into your app, it adds an additional 10K of "resting" memory usage, and perhaps 20K or more of peak memory usage due to the overhead of converting the JSON text to binary data.

    Now if you have the same data with X languages, your peak memory usage could be X times as large, which could lead to a crash. (Ofc this assumes that peak memory usage is happening at the point that you load resources, which may or may not be the case.)

    Probably not an issue in your case, with such a tiny amount of data. And ofc your app may be running on devices which have plenty of memory regardless.

    Another way solution could be to put the language ID in the JSON id itself.

    e.g.

    <jsonData id="directionText_lang_0">
        ["N", "NE", "E", "SE", "S", "SW", "W", "NW", "N"]
    </jsonData>
    <jsonData id="directionText_lang_8389360">
        ["É", "ÉK", "K", "DK", "D", "DNY", "NY", "ÉNY", "É"]
    </jsonData>

    This might be a better solution if you have large amounts of data, and/or a large number of languages.

  • It sound nice, bot how you build a dinamic resource name? I do not know this deep the MonkeyC.