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

LocalizationService does not set a culture in Windows (Unpackaged) Head #2133

Open
Tracked by #2139
Seekuhnetz opened this issue Jan 3, 2024 · 21 comments · Fixed by #2179
Open
Tracked by #2139

LocalizationService does not set a culture in Windows (Unpackaged) Head #2133

Seekuhnetz opened this issue Jan 3, 2024 · 21 comments · Fixed by #2179
Assignees
Labels
kind/bug Something isn't working

Comments

@Seekuhnetz
Copy link

Seekuhnetz commented Jan 3, 2024

Current behavior

I created a new App with the UnoApp Template and Localization and Configuration enabled.
I added the ToggleLocalizationAsync() of this page.

The Current Culture gets updated in the (Packaged) but not in the (Unpackaged) Windows Head.

I also had to add .Section<LocalizationConfiguration>() under configBuilder in my App.cs else the SupportedCultures would be empty.
I guess the problem could be fixed if i was able to also add .Section<LocalizationSettings>(). But i can not because it is internal.

Expected behavior

The Current Culture should be updated in the (Unpackaged) Windows Head like in the (Packaged) Head.

How to reproduce it (as minimally and precisely as possible)

  • Create a new Uno App with the UnoApp Template and Localization and Configuration enabled.
  • Add the ToggleLocalizationAsync() of this page.
  • Run the Windows (Unpackaged) Head

Workaround

No response

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

Windows

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

@Seekuhnetz Seekuhnetz added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification. labels Jan 3, 2024
@jeromelaban jeromelaban transferred this issue from unoplatform/uno Jan 8, 2024
@Seekuhnetz
Copy link
Author

@nickrandolph
I just tested this and it looks like that changing the language with ILocalizationService still does not work in the Unpackaged Head of WinUI.
Packaged Head works fine.
SetLanguageTest.zip

@nickrandolph
Copy link
Contributor

nickrandolph commented May 20, 2024

@nickrandolph I just tested this and it looks like that changing the language with ILocalizationService still does not work in the Unpackaged Head of WinUI. Packaged Head works fine. SetLanguageTest.zip

Thanks for following up on this. I've confirmed that:

  • ILocalizationService does appear to be saving the change to the current culture
  • For some reason the saved culture isn't being applied correctly when run as unpackaged.
    This is evident both in a new application created with latest template but also in the Playground application in this repository

@nickrandolph nickrandolph reopened this May 20, 2024
@nickrandolph
Copy link
Contributor

Looks like we might be stalled on this microsoft/WindowsAppSDK#4181

@nickrandolph nickrandolph removed the triage/untriaged Indicates an issue requires triaging or verification. label May 22, 2024
@Seekuhnetz
Copy link
Author

Seekuhnetz commented May 31, 2024

I also noticed that DateTimes are in the wrong format for the Unpackaged Head.
The culture does not get set to the system one and is instead set to "en".
Again this is not an issue in the Packaged Head.

I fixed the issue with following workaround:

App.Dispatcher.TryEnqueue(() =>
{
    CultureInfo ci = new CultureInfo("de-DE");
    Thread.CurrentThread.CurrentCulture = ci;
    Thread.CurrentThread.CurrentUICulture = ci;
});

@Seekuhnetz
Copy link
Author

@nickrandolph it looks like microsoft/WindowsAppSDK#4181 has been closed.

@agneszitte
Copy link
Contributor

@nickrandolph it looks like microsoft/WindowsAppSDK#4181 has been closed.

@rajamatt now that microsoft/WindowsAppSDK#4181 is closed, can you re-test with latest version please
You can start to test with 1.6.240701003-experimental2 as mentioned here normally.

@agneszitte agneszitte assigned rajamatt and unassigned kazo0 and rajamatt Aug 29, 2024
@rajamatt
Copy link
Contributor

rajamatt commented Aug 29, 2024

I created a new app using Uno.WinUI 5.3.123 and the culture localization was working well in both Packaged and Unpackaged Windows. The Microsoft.WindowsAppSDK version (1.5.240627000) I used is the same that comes with Uno.WinUI 5.3.123. In the uno.extensions Playground, updating the Uno.WinUI to 5.3.123 does not solve the issue though.

I did not test with 1.6.240701003-experimental2 yet as I am having trouble overriding the version that it takes from Uno.WinUI in Playground. This should be the next step.

@rajamatt
Copy link
Contributor

rajamatt commented Sep 4, 2024

I found a way to substitute the Microsoft.WindowsAppSDK package with the 1.6.240701003-experimental2 version. It is still working in Packaged and Unpackaged with Uno.WinUI 5.3.123 (which is used with Uno.Sdk 5.3.99).

However, if I override the Microsoft.WindowsAppSDK in Playground it still doesn't work, so something might be wrong with Playground itself.

It seems that this 1.6.240701003-experimental2 version doesn't help. I also tried the latest version 1.6.240821007-preview2 which didn't help either.

@agneszitte Could you also quickly test if a new unoapp with Uno.Sdk 5.3.99 handles the localization change correctly? You can:

  1. Create a new unoapp with the recommended preset.
  2. In the MainModel add the method below, along with the localizationService, like done on this doc page. And bind it to a button on the MainPage.
public Task ToggleLocalizationAsync()
{
    var currentCulture = localizationService.CurrentCulture;
    var culture = localizationService.SupportedCultures.First(culture => culture.Name != currentCulture.Name);
    
    return localizationService.SetCurrentCultureAsync(culture);
}
  1. Open the app, observe the title of the application (with the recommended template it should be Main - [name of app] - [language])
  2. Click the button you binded to the localization toggle method.
  3. Close the app, then start it again.
  4. Notice the language in the title of the application should have changed (localization worked).

@agneszitte agneszitte assigned Kunal22shah and unassigned rajamatt Sep 17, 2024
@agneszitte
Copy link
Contributor

@Kunal22shah can you help do a test with latest 1.6.240829007 please

@Kunal22shah
Copy link
Contributor

@agneszitte I have tested with Uno.Sdk 5.3.108 and latest 1.6.240829007 WinAppSdk and can confirm that localization works fine.

@rajamatt
Copy link
Contributor

@Kunal22shah Thanks for the help 🚀

@agneszitte I want to re-test pure Xaml culture/localization as well as I don't remember clearly if it was working or not. I will report the result here.

@rajamatt rajamatt self-assigned this Sep 19, 2024
@agneszitte
Copy link
Contributor

agneszitte commented Sep 19, 2024

@Kunal22shah Thanks for the help 🚀

@agneszitte I want to re-test pure Xaml culture/localization as well as I don't remember clearly if it was working or not. I will report the result here.

Thanks a lot @Kunal22shah for the previous test and thanks in advance for the result of the next test @rajamatt

@rajamatt
Copy link
Contributor

Tested again with latest stable Uno.Sdk and both: Code behind & Xaml X:Uid's are working correctly on the Unpackaged Windows head.

Launching the app, setting the culture, then restarting the app displays the correct selected culture.

@agneszitte
Copy link
Contributor

Tested again with latest stable Uno.Sdk and both: Code behind & Xaml X:Uid's are working correctly on the Unpackaged Windows head.

Launching the app, setting the culture, then restarting the app displays the correct selected culture.

Thanks a lot for the feedback @rajamatt !

@rajamatt
Copy link
Contributor

rajamatt commented Oct 1, 2024

I retested and am not able to make localization work on the Unpackaged head. I am not sure what happened but I am guessing I overrode the WinAppSdk to the preview version and then Extensions always kept that version. It is weird though, because that specific preview version adds to the API with Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride, and I never changed code in Extensions when I was testing, so it really should not have worked at all.

More importantly, this new Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride is only available in the WindowsAppSdk 1.6.240821007-preview2 version, and not the latest stable 1.6.240829007.

@rajamatt rajamatt reopened this Oct 1, 2024
@rajamatt
Copy link
Contributor

rajamatt commented Oct 1, 2024

WinAppSdk seems to just have been updated and now includes this change (on a stable version!) I will test further to see if this new version 1.6.240923002 helps.

@Seekuhnetz
Copy link
Author

WinAppSdk seems to just have been updated and now includes this change (on a stable version!) I will test further to see if this new version 1.6.240923002 helps.

thank you.
how can i reference 1.6.240923002 in my project?
in the NuGet Manager it is said that i can not upgrade the NuGet as it is referenced by the Uno Sdk

@agneszitte
Copy link
Contributor

agneszitte commented Oct 1, 2024

thank you. how can i reference 1.6.240923002 in my project? in the NuGet Manager it is said that i can not upgrade the NuGet as it is referenced by the Uno Sdk

@Seekuhnetz if you want to give it a try on your side while @rajamatt is testing it on his side, you can add in your Name_Of_Your_Project.csproj file <WinAppSdkVersion>1.6.240923002</WinAppSdkVersion>

For more info about implicit packages:
https://platform.uno/docs/articles/features/using-the-uno-sdk.html?tabs=3rd-party-packages#implicit-packages

@Seekuhnetz
Copy link
Author

Seekuhnetz commented Oct 1, 2024

1.6.240923002

thank you, but sadly this did not fix the bug for me.

From @agneszitte:
@Seekuhnetz Thank you a lot for the feedback, I will see if @rajamatt confirm the same on his side as well.

@rajamatt
Copy link
Contributor

rajamatt commented Oct 2, 2024

Thanks for the test @Seekuhnetz. I believe this will require a fix in the Uno.Extensions.Localization project as over there we are currently setting the PrimaryLanguage property which isn't compatible with Unpackaged apps.

I will investigate more to prepare the details and share them here.

@agneszitte
Copy link
Contributor

Thanks for the test @Seekuhnetz. I believe this will require a fix in the Uno.Extensions.Localization project as over there we are currently setting the PrimaryLanguage property which isn't compatible with Unpackaged apps.

I will investigate more to prepare the details and share them here.

cc @kazo0, @eriklimakc for info

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants