Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
YegorStepanov opened this issue Sep 21, 2021 · 9 comments
Labels
area-MRT This area only covers the usage of MRT inside of a WinUI 3 app bug Something isn't working fix-released The fix has been in a release (experimental, preview, stable, or servicing). group-language product-winui3 WinUI 3 issues team-Markup Issue for the Markup team v1.0.0-preview1
Milestone

Comments

@YegorStepanov
Copy link

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
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Sep 21, 2021
@StephenLPeters StephenLPeters added product-winui3 WinUI 3 issues team-Markup Issue for the Markup team v1.0.0-preview1 labels Sep 22, 2021
@StephenLPeters
Copy link
Contributor

@fabiant3 FYI

@quangtrang1111
Copy link

I also got this exception like below when run as Unpackage in version 1.0.
Anyone can help?

image

@StephenLPeters
Copy link
Contributor

@MikeHillberg and @codendone FYI as well

@ynborokh
Copy link

ynborokh commented Jun 8, 2022

@YegorStepanov @StephenLPeters Is it really a bug? According to the documentation:

When you set the PrimaryLanguageOverride, this is immediately reflected in the ApplicationLanguages.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.

@YegorStepanov
Copy link
Author

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.

@evelynwu-msft evelynwu-msft added the area-MRT This area only covers the usage of MRT inside of a WinUI 3 app label Nov 29, 2022
@bpulliam bpulliam removed the needs-triage Issue needs to be triaged by the area owners label Dec 6, 2022
@MichaelJachan
Copy link

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

@JoeTomkinson
Copy link

Two years on and this still appears to be, assumeably, not a priority.

It's possible to spin up our own version of language resource management which can be applied appropriately upon language change to the relevant UI components; but that seems like a lot of work for something which probably should be handled the same way bindeable properties are updated across the UI layout.

I can't seem to find where microsoft-ui-xaml or the WinSDK resolve resw files, would be more than happy to take a look if someone can point me in the right direction.

@duncanmacmichael duncanmacmichael added the bug Something isn't working label Oct 31, 2023
@ghost1372
Copy link
Contributor

@duncanmacmichael i tested with v1.6-exp2 and now we can use
Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "fa-IR";
and everything is working fine, and i think this issue can be closed

@codendone
Copy link
Contributor

Thanks, @ghost1372!

Closing as fixed in 1.6.240701003-experimental2 via microsoft/WindowsAppSDK#4523.

@llongley llongley reopened this Jul 8, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Jul 8, 2024
@JesseCol JesseCol removed the needs-triage Issue needs to be triaged by the area owners label Jul 25, 2024
@codendone codendone added this to the WinAppSDK 1.6 milestone Aug 22, 2024
@codendone codendone added the fix-released The fix has been in a release (experimental, preview, stable, or servicing). label Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-MRT This area only covers the usage of MRT inside of a WinUI 3 app bug Something isn't working fix-released The fix has been in a release (experimental, preview, stable, or servicing). group-language product-winui3 WinUI 3 issues team-Markup Issue for the Markup team v1.0.0-preview1
Projects
None yet
Development

No branches or pull requests