Custom localization for language support in order to change the language-resource runtime

OscisOscis Member ✭✭

Hello,

I need to fetch new words or language-libs from a server (JSON) and save/update them locally on the device. I was wondering what the best way would be to do this. Since the current localization support in Xamarin uses embedded resources, I need to save these values somewhere else.

What do you guys think would be the best, to use App-settings or maybe a SQLite db? Or is there another (more simple) way. Would it be possible to save the JSON from the server and read straight from this?

Best Answer

Answers

  • OscisOscis Member ✭✭

    Thanks

  • MakMak INMember ✭✭

    @Oscis
    Could you replace localization source from embedded resource(resx files) to downloaded json data/files? Can you suggest me how to achieve that?

  • OscisOscis Member ✭✭

    I never found a good solution for this. But what I did was to create a TranslationObject which was exposed in a base-class for my ViewModels. Then I could bind to the translations in the xaml. The TranslationObject called a TranslationService which would read/update all the langs and translations from the JSON-file in local-storage into key-value collection (On start or when updated).

    Then bind in xaml like usual:

    Text="{Binding TranslationObject.Word}"

  • batmacibatmaci DEMember ✭✭✭✭✭
    How is the performance with this approach. Because embedded resources are faster than json objects if I know right.
  • OscisOscis Member ✭✭

    @batmaci said:
    How is the performance with this approach. Because embedded resources are faster than json objects if I know right.

    I haven't measured, but it only reads the Json once async into memory (we dont have that many translations).

Sign In or Register to comment.