uno.extensions
uno.extensions copied to clipboard
LocalizationService does not set a culture in Windows (Unpackaged) Head
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
@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 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
Looks like we might be stalled on this https://github.com/microsoft/WindowsAppSDK/pull/4181
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;
});
@nickrandolph it looks like https://github.com/microsoft/WindowsAppSDK/pull/4181 has been closed.
@nickrandolph it looks like microsoft/WindowsAppSDK#4181 has been closed.
@rajamatt now that https://github.com/microsoft/WindowsAppSDK/pull/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.
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.
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:
- Create a new unoapp with the recommended preset.
- 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);
}
- Open the app, observe the title of the application (with the recommended template it should be
Main - [name of app] - [language]) - Click the button you binded to the localization toggle method.
- Close the app, then start it again.
- Notice the language in the title of the application should have changed (localization worked).
@Kunal22shah can you help do a test with latest 1.6.240829007 please
@agneszitte I have tested with Uno.Sdk 5.3.108 and latest 1.6.240829007 WinAppSdk and can confirm that localization works fine.
@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.
@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
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.
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 !
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.
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.
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
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
<WinAppSdkVersion>1.6.240923002</WinAppSdkVersion>
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.
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.
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
@agneszitte Is there any update for this ticket?