question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[iOS] Localisation not working

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
AnatolyChugaevcommented, May 26, 2022

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.

0reactions
jfversluiscommented, Aug 17, 2022

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: https://github.com/dotnet/runtime/issues/73512#issuecomment-1213464568

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

localization - Localizable.strings not working in iOS
I filled up these files with the language translations, did a build/clean and then a fresh build, but there is no way the...
Read more >
Localization not loading in some cases
If so, there is an old bug: UITextView text are not localized from Localizable.Strings with the text as key. Need to call with...
Read more >
Resolved - Localisation Not Working for iOS
In the Unity editor, the localization setup working properly but when I first time installed the game on the iPhone, It is not...
Read more >
Localization on iOS - Hipo
Localization is an important area while developing your app. iPhone and iPad users who don't speak English easily outnumber the ones who do!...
Read more >
how to localize iOS apps with string examples
Step 1: Create Localizable.strings file · Step 2: Adding languages · Step 3: Working with translations · Tip #1: The shortcut · Tip...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found