dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.89k stars 524 forks source link

.NET MAUI Blazor Hybrid Localization issue #8972

Open PureWeen opened 1 month ago

PureWeen commented 1 month ago

Issue moved from dotnet/maui#22551


From @bpsc-wkubis on Tuesday, May 21, 2024 2:17:12 PM

Description

I have basically followeed jfversluis on Maui Blazor hybrid localization, which can be found here

However, I've encountered an issue when trying to preserve localization settings in Preferences. Specifically, once the culture is set when the app starts, it becomes impossible to change it later. The code causing this issue is as follows

var language = Preferences.Get("language", "en-US");
var culture = new CultureInfo(language);

Thread.CurrentThread.CurrentCulture = culture;
Thread.CurrentThread.CurrentUICulture = culture;
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

By commenting out this code ni App.xaml.cs, we enable the culture change to function correctly. However, this leaves us without a mechanism to maintain the set culture across application restarts

In video this problem does not occur because navigation was not performed. When we actually would navigate to counter page and then back to home, language will be same as app has set in start in App.xaml.cs.

Steps to Reproduce

Clone the application from the repository, switch the language setting to 'pl-PL', navigate to a different page such as the 'Counter' page, and then return to the main page where the Localizer with resources is located.

Link to public reproduction project repository

https://github.com/bpsc-wkubis/maui-blazor-hybrid-localization-issue

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

PureWeen commented 1 month ago

Issue moved from dotnet/maui#22551


From @github-actions[bot] on Tuesday, May 21, 2024 2:17:39 PM

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.