ApplicationLanguages.PrimaryLanguageOverride doesn't update x:Uid without restarting the app
See original GitHub issueDescribe the bug
After setting ApplicationLanguages.PrimaryLanguageOverride
, the new pages use old x:Uid
. Restart only refresh it. The code below updates x:Uid
in UWP but doesn’t in WinUI.
The following sub-links also don’t solve the problem: UWP - Change of Languages
Are in WinUI the way to update x:Uid in runtime without manually updating strings in response to qualifier value change events?
Steps to reproduce the bug Steps to reproduce the behavior:
- Add “Hello.Text” to
Strings/en/Resources.resw
and toStrings/ru/Resources.resw
- Assign
x:Uid
toTextBlock
- Copy templated UWP code from
OnLaunched
and eliminate the errors (base.Frame
is null by default in WinUI) - Add handler to button:
private void myButton_Click(object sender, RoutedEventArgs e)
{
string lang = ApplicationLanguages.PrimaryLanguageOverride is "en" ? "ru" : "en";
ApplicationLanguages.PrimaryLanguageOverride = lang;
ResourceContext.GetForViewIndependentUse().Reset();
Frame.Navigate(typeof(MainPage)); //old
new Window { Content = new MainPage() }.Activate(); //old
//it works, but not in XAML
string newLanguage = ResourceLoader.GetForViewIndependentUse().GetString("Hello/Text");
}
Expected behavior
The newly created Page
/Window
has the desired localizated x:Uid
.
Version Info [WinUI 3 - Windows App SDK 0.8: 0.8.0] [WinUI 3 - Windows App SDK 1.0.0-preview1]
Windows app type:
UWP | Win32 |
---|---|
Yes |
Windows version | Saw the problem? |
---|---|
Insider Build (22000) | Yes |
May 2021 Update (19043) | |
October 2020 Update (19042) | |
May 2020 Update (19041) | |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Xbox | |
Surface Hub | |
IoT |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Changing language in UWP doesn't change system ...
xaml - Changing language in UWP doesn't change system features language - only on app restart - Stack Overflow.
Read more >ApplicationLanguages.PrimaryLanguageOverride Property
When your app gets the value, PrimaryLanguageOverride returns either a single language tag (if your app has previously set the property) or an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As far as I know, WinUI 3 is a continuation of UWP, and if something doesn’t work and there are no docs that say it deprecated/can’t be applied, then it is bug.
Whether it’s a bug or not, reloading the app to change the language is a bad UX.
Hello all!
I am starting now with WinUI 3 localization (Win10, Community Toolkit and WinUI 3 at the latest versions (as of July 2023). My .NET libraries are updating the newly set language at runtime:
CultureInfo.CurrentUICulture = new CultureInfo(newLanguage);
My WinUI 3 Projects do not; but it is updated on App restart:
ApplicationLanguages.PrimaryLanguageOverride = newLanguage;
I would like you @ynborokh to give us an example of
“listen to the QualifierValues property on a default resource context and take whatever actions may be needed to reload resources”
And i wonder (in my humble experience) why the at-runtime-WinUI3-Language-Update could not be an async Method(), that, once finished, has done all the resource-reloading?
Best, MJ:)