MvvmCross Localization: Switching at Runtime

Is there a way to change the current language to another at runtime?

For example: to be able to switch when a button is pressed or when the application starts, get the user's language and switch.

How to tell the plugin to check the user's language at startup?

Thanks in advance for your help.

+4
source share
1 answer

Is there a way to change the current language to another at runtime?

yes, call builder.LoadResources(whichLanguage) on MvxTextProviderBuilder.cs

For example: be able to switch when a button is pressed

The user interface is not really configured to switch in real time. When you switch between languages, the new JSON resource files will be loaded in order, but the existing display text will not be updated. This is a bit like most mobile operating systems - if you want to switch languages, you often have to reboot!

If you want to add dynamic switching, you will need to find a way to tell the user interface to completely update the entire text - I suspect that it will not be easy to do, but for each page some manual encoding / View, which has already been created and displayed, may be required: /

or when starting the application, get the user language and switch.

This is a much simpler way to make i18n. This is usually normal because MvvmCross is mainly aimed at phones - and phones are usually single-user devices that don't often switch languages.

  • You can, for example, use some variable (for example, System.Globalization.CultureInfo.CurrentUICulture ) to develop a better display language.

  • Or do you find at boot time whether the user still selected the language - if there are any, then show the HomeViewModel - if they do not show then the LanguagePickerViewModel is what we did in StarWarsKinect - StartNavigationObject - the perfect place for such logic!

SWK Language Pick

How to tell the plugin to check the user's language at startup?

Currently, you will have to code this logic as part of your application launch.

I would definitely be ready to provide an improved plugin on this - perhaps with a demo!


If you are looking for i18n, then one alternative implementation that should be considered is Vernacular - the Rdio team has a very good offer for Mono and MS platforms - https://github.com/rdio/vernacular

+2
source

Source: https://habr.com/ru/post/1446962/


All Articles