Localization on the fly in the WinRT application

In the WinRT application, the new localization is applied when the application is restarted (using code or by changing the language from the control panel). What if I want to change localized strings on the fly without restarting the application?

Suppose I have a combo box with different languages. If the user selects a language, all lines will be translated using the resource.

I came across this code, but it only works if I put it in the constructor of the App , which is also on startup. I cannot do this with a static method since it does not work.

 var culture = new System.Globalization.CultureInfo("en-US"); Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = culture.Name; System.Globalization.CultureInfo.DefaultThreadCurrentCulture = culture; System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = culture; 

I want something like below this image. Image from a CodeProject article.

enter image description here

+7
c # windows-8 windows-store-apps windows-runtime winrt-xaml
source share
2 answers

You need to reset the resource manager context.

For Windows 8.1:

 var resourceContext = Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView(); resourceContext.Reset(); 

You still need to force the page to redraw itself and thus re-request resources for the changes to occur. For Windows 8, you can see https://timheuer.com/blog/archive/2013/03/26/howto-refresh-languages-winrt-xaml-windows-store.aspx

Please note that the PrimaryLanguageOverride is saved and from your description of the problem it looks as if you correctly configured it in response to a user-initiated action. I do not think you need to redefine threadinfos technology unless the user also initiates the change.

Note also that PrimaryLanguageOverride accepts a BCP 47 language tag, while CultureInfo uses a locale name that has subtle differences.

+6
source share

I never try to do this, but I can say if you are developing an application in Windows 8, then the application will not have such a method as changing the map.

But you can achieve your functionality by following 1 Executing a function that should read the language of the resource when changing an event with a list. 2. Make sure you save certain arguments in the local setting. 3. After that, you just need to implement the refresh function, which can refresh your page by changing the language. All the best .. !!

0
source share

All Articles