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

[iOS] Localisation not working #7362

Closed
PedroCigaw opened this issue May 20, 2022 · 10 comments
Closed

[iOS] Localisation not working #7362

PedroCigaw opened this issue May 20, 2022 · 10 comments
Labels
area-localization Localization and globalization issues platform/iOS 🍎 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@PedroCigaw
Copy link

Description

Running an iOS app I want to be able to get the localisation information from the user settings.

On startup the values for the following are all set to "Invariant"
Thread.CurrentThread.CurrentUICulture
Thread.CurrentThread.CurrentCulture
CultureInfo.CurrentUICulture
CultureInfo.DefaultThreadCurrentUICulture
CultureInfo.DefaultThreadCurrentCulture
CultureInfo.InstalledUICulture
CultureInfo.InvariantCulture

Note: On windows and andriod these values are set correctly.

I have tried to get the localisation information to create a cultureinfo and set the values for the above properties in the AppDelegate class, I have tried to get the localization information from NSLocale.CurrentLocale or NSLocale.AutoUpdatingCurrentLocale.CollationIdentifier but it always return null. I can see the values in the debug window but on running the code to get the LocaleIdentifier throw a NullReferenceException. I have tried the following code in the overrides for CreateMauiApp, WillFinishLaunching and OnActivated.

`

var culture = CultureInfo.CreateSpecificCulture(NSLocale.CurrentLocale.CollationIdentifier);
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;

`

Firstly I would have expected the CultureInfo to have been which would be consistent with Windows and Android targets, failing that I would have expected I should have been able to access the NSLocale.CurrentLocale properties.

Sample repo available here https://github.com/PedroCigaw/MauiIssueSamplesRepo.git

Steps to Reproduce

  1. Run sample from github
  2. Run on windows and android you you will see the cultureinfo is loaded.
  3. Run on ios see cultureinfo is Invariant.
  4. Open AppDelegate.cs and uncomment code.
  5. Run on ios and the app will crash

Version with bug

Release Candidate 3 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 15

Did you find any workaround?

No work round

Relevant log output

No response

@PedroCigaw PedroCigaw added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels May 20, 2022
@Eilon Eilon added the area-localization Localization and globalization issues label May 20, 2022
@Eilon
Copy link
Member

Eilon commented May 20, 2022

Possible dup of dotnet/runtime#68321

@PedroCigaw
Copy link
Author

Maybe for the invariant culture, but not for the crashing when accessing NSLocale.CurrentLocale which is returning null. Weird that when you set a breakpoint and debug you can interrogate the values but in code its null so accessing any properties causes the app to just crash.

@VincentBu
Copy link

repro with vs main build(32522.39.main)

@VincentBu VincentBu added s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels May 23, 2022
@AnatolyChugaev
Copy link

Hello, we are developing DevExpress .NET MAUI controls and experienced the same issue. This issue has a Normal priority for us. Thank you for your help.

@ANicholasson
Copy link

Hi, I'm also experiencing this issue. Would be nice to know if there is a workaround or when to expect this will be fixed.

@JonWeighell
Copy link

This is also affecting MAUI hybrid-Blazor apps - my iPhone is set to UK English, but the culture settings are just coming through to the app as null, and the app is being rendered incorrectly as en-US by default.

This is working and performing correctly on Android and Windows and the app is rendered as en-GB. This is a critical bug for us as dates are being formatted incorrectly. Many thanks!

@AntonKosenkoDX
Copy link

@VincentBu Hello! Any update on this issue?

@pierre01
Copy link

I have the same issue!
Any Updates?

@cris-m
Copy link

cris-m commented Aug 8, 2022

Any Update? I am facing the same issues. The culture is always invariant culture. EnglishName is the same as TwoLetterISORegionName.
Screen Shot 2022-08-07 at 16 58 36

@jfversluis
Copy link
Member

As Eilon pointed out, this is a bug in the runtime. The bug is fixed and released for the 6.0.3xx band but not released for the 6.0.4xx band yet, hopefully that will happen soon. If you need this right now, you can create a global.json file that you set to a version in the 3xx with a minimum of 303 range.

  1. Run dotnet --list-sdks
  2. Find a version that starts with 3, the version needs to be at least 6.0.303 (which is the highest at the time of writing)
  3. In your project root run dotnet new --globaljson --sdk-version=6.0.303
  4. Run dotnet workload update NOTE: this will update your entire MAUI workload for all projects
  5. Restart Visual Studio to be sure it uses 6.0.303 and aggressively rebuild your project

You can see if it worked by inspecting CultureInfo.CurrentUICulture.DisplayName which should not contain "invariant"

More is described here: dotnet/runtime#73512 (comment)

If you do not need this today, wait until the next .NET 6 update and it should be released as part of that. There is nothing we can do at this time on our end.

@jfversluis jfversluis closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-localization Localization and globalization issues platform/iOS 🍎 s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests