question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ApplicationLanguages.PrimaryLanguageOverride doesn't update x:Uid without restarting the app

See original GitHub issue

Describe 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:

  1. Add “Hello.Text” to Strings/en/Resources.resw and to Strings/ru/Resources.resw
  2. Assign x:Uid to TextBlock
  3. Copy templated UWP code from OnLaunched and eliminate the errors (base.Frame is null by default in WinUI)
  4. 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:open
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
YegorStepanovcommented, Jun 9, 2022

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.

0reactions
MichaelJachancommented, Jul 19, 2023

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:)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found