Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing language in UWP doesn't change system features language - only on app restart

I have a UWP application.

And i have a need to change locale on the fly, so i have this for language changing:

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = language.FourDigitCode;
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();

But there is a problem that system features language doesn't switch ( only after application relaunch ) how can i fix it?

Here is an example:

enter image description here

Now i run this code:

Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "lv-LV";
ResourceContext.GetForViewIndependentUse().Reset();
ResourceContext.GetForCurrentView();

The UI gets localized, but system features still remain unlocalized:

enter image description here

But when i restart the app, all is OK:

enter image description here

Any ideas how can i fix it?

like image 262
Cheese Avatar asked Mar 17 '17 13:03

Cheese


1 Answers

I'm afraid there is no fix for this and what you've seen is by design. Ref Remarks of PrimaryLanguageOverride property:

When you set the PrimaryLanguageOverride, this is immediately reflected in the Languages property. However, this change may not take effect immediately on resources loaded in the app UI. To make sure the app responds to such changes, you can listen to the QualifierValues property on a default resource context and take whatever actions may be needed to reload resources. Those requirements may vary depending on the UI framework used by the app, and it may be necessary to restart the app.

For your scenario, a restart is needed. I'd suggest that you can add a tip to tell users to restart the app and also a button to close the app like what used in News App. enter image description here
And to close the app, we can call Application.Exit method like the following.

Application.Current.Exit();
like image 176
Jay Zuo Avatar answered Oct 19 '22 16:10

Jay Zuo