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

  • Good point - I should've elaborated on how to actually load the resources haha. Yeah that part would lead to additional complexity (and memory usage), so it would have to be weighed against the size of resources. It might still be worth it for very large data and/or a large number of languages.

    You would have to create a lookup table (dictionary) mapping language ID to resource ID, since resource IDs (symbols) indeed cannot be built dynamically (e.g. by string concatenation).

    Ofc if you're loading a lot of resources, the resource ID lookup itself could accomplished using a generic function which takes the resource id lookup dictionary as input.

  • Yeah, I think yours is also a nice solution, a bit hardcoded but for the large data is better than mine. vote :)

  • I guess this is just one example, but how many actual strings do you have? For just these 8 strings I would add them as regular strings and load them into the array (or maybe find a better way, we font see how you use them and why it starts and ends with north)

  • Its simple, this is a compass label, 0 is north. It is easy and compact way to show the direction with text. The other internationalized texts in string but this I need in array format. 

    Math.round(pHeadingValue / 45).toNumber()

    There is many possible way to solve this, but because I plan to use only 2 language my solution is a shortcut and working well :)

  • If you only have this array of strings, and you don't have 240+ other strings, then I would totally do what I recommended above. I don't even understand why you started to do it with JSON instead of strings. Create a constant array with 9 elements of the 8 string symbols, and in a for loop load the strings into an array that you can use exactly as now. I bet it will not be significantly more code than you have now, and will be even less compared to the code FlowState sent to fix the problem. Plus your app will be ready to be translated to more languages. Már ha érdekel a magyaron és angolon kívül más nyelv is.

  • Yes, as I said there is many way to solve my problem. Included put the directions into separated string (like CSV) or make 4 string (that is enough, no need 8) and combine it into array, etc, etc, etc.

    But the original problem is still here, JSON resource working incorrect if you use in language resources folder.

    Mine was only just a humble reminder, the problem is still here after 3 years :(

  • Yeah, that's true. Maybe you should open a bug report about it (so that it can be acknowledged in 2028 ;)

  • Just for you :D (but this is really special, because the directions actually IRL also building with this logic)

            var n = WatchUi.loadResource( Rez.Strings.N ) as String;
            var w = WatchUi.loadResource( Rez.Strings.W ) as String;
            var e = WatchUi.loadResource( Rez.Strings.E ) as String;
            var s = WatchUi.loadResource( Rez.Strings.S ) as String;
            
            _directionTexts = [n, n+e, e, s+e, s, s+w, w, n+w, n];

  • Exactly, though if real i18n (or actually this is probably l11n) interests you I wouldn't assume that in all the languages you can concatenate them that way, but maybe that's for another discussion Slight smile

  • But the original problem is still here, JSON resource working incorrect if you use in language resources folder.

    Mine was only just a humble reminder, the problem is still here after 3 years :(

    As I mentioned, I believe this is by design - i.e. that language-specific resources are only supported for strings, and no other resource types.

    As flocsy suggested, you could always post in the bug reports forum, so Garmin could confirm or deny my guess.