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 Maui sample app uses Chinese Simplified when Chinese Traditional is set in phone preferences #102560

Closed
Czapek83 opened this issue May 21, 2024 · 15 comments

Comments

@Czapek83
Copy link

Description

Created new maui project. Created Strings.resx, Strings.zh.resx, Strings.zh-Hans.resx, and Strings.zh-Hant.resx files with below values of SampleText:
image

On MainPage.xaml added label that will display proper text according to current language:
image

And now, when setting Iphone Region to "China mainland" and language to "Chinese Traditional", the SampleText is taken from Chinese, Simplified, but should be taken from Chinese, Traditional:
image

Steps to Reproduce

  1. Create new maui project.
  2. Create localized strings in Resources (Strings.zh-Hans.resx for Chinese Simplified and Strings.zh-Hant for Chinese Traditional) with different strings in it.
  3. Use localized string in one of your screens
  4. Change your Iphone region to "China mainland" and language to "Chinese Traditional".
  5. Run your application and you can see that Chinese Simplified string is used.

Link to public reproduction project repository

https://github.com/Czapek83/Chinese_LanguageIssue

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

IOS 16.7.7, IOS 17.4.1

Did you find any workaround?

Unfortunatelly, not at all.

Relevant log output

No response

Copy link
Contributor

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.

@PureWeen

This comment was marked as outdated.

@dotnet dotnet locked and limited conversation to collaborators May 21, 2024
@rolfbjarne
Copy link
Member

I can reproduce this.

Adding the following in the managed Main method:

Console.WriteLine ($"CurrentCulture: {Thread.CurrentThread.CurrentCulture.Name}");
Console.WriteLine ($"CurrentUICulture: {Thread.CurrentThread.CurrentUICulture.Name}");
Console.WriteLine ($"NSLocale.CurrentLocale.LocaleIdentifier: {NSLocale.CurrentLocale.LocaleIdentifier}");
Console.WriteLine ($"NSLocale.CurrentLocale.CountryCode: {NSLocale.CurrentLocale.CountryCode}");
Console.WriteLine ($"NSLocale.CurrentLocale.LanguageCode: {NSLocale.CurrentLocale.LanguageCode}");
Console.WriteLine ($"NSLocale.CurrentLocale.ScriptCode: {NSLocale.CurrentLocale.ScriptCode}");

prints:


CurrentCulture: zh-CN
CurrentUICulture: zh-CN
NSLocale.CurrentLocale.LocaleIdentifier: zh-Hant_CN
NSLocale.CurrentLocale.CountryCode: CN
NSLocale.CurrentLocale.LanguageCode: zh
NSLocale.CurrentLocale.ScriptCode: Hant

Debugging a bit it seems we hit this code path:

if ([currentLocale.languageCode length] > 0 && [currentLocale.countryCode length] > 0)
{
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode];
}

which means the current (ui) culture is determined using the current locale's LanguageCode-CountryCode (which results in "zh-CN"), not the locale's LocaleIdentifier, nor taking into account the ScriptCode value (which both contain "Hant").

@rolfbjarne rolfbjarne reopened this May 22, 2024
@dotnet dotnet unlocked this conversation May 22, 2024
@rolfbjarne rolfbjarne transferred this issue from dotnet/maui May 22, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 22, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 22, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-globalization
See info in area-owners.md if you want to be subscribed.

@tarekgh tarekgh removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 23, 2024
@tarekgh
Copy link
Member

tarekgh commented May 23, 2024

CC @steveisok

@steveisok
Copy link
Member

/cc @vitek-karas

@lewing
Copy link
Member

lewing commented May 23, 2024

cc @mkhamoyan

@vitek-karas
Copy link
Member

/cc @matouskozak

@matouskozak
Copy link
Member

Can confirm that the issue is reproducible with .NET 8. Works as expected with .NET 9.

@lewing
Copy link
Member

lewing commented May 24, 2024

Is the issue how we construct the icu locale in net8.0 or the fact that we've potentially removed the required information from the icu bundle we produce for size reasons?

@matouskozak
Copy link
Member

Is the issue how we construct the icu locale in net8.0 or the fact that we've potentially removed the required information from the icu bundle we produce for size reasons?

I'm unsure, I have thought that we have full ICU when hybrid globalization is not enabled on .NET 8 (do you know @mkhamoyan ?).

I did some digging and the correct language can be set using [[NSLocale preferredLanguages] objectAtIndex:0] (returns expected zh-Hant-CN).

@mkhamoyan
Copy link
Contributor

@matouskozak We have whitelisted locales for ICU in net8.0 https://github.com/dotnet/icu/blob/dotnet/main/icu-filters/icudt_mobile.json#L8-L194 and I don't see here zh-Hant_CN.
For hybrid mode we do get default locale using preferedLanguages as you mentioned

return strdup([NSLocale.preferredLanguages[0] UTF8String]);

@sowacx
Copy link

sowacx commented May 28, 2024

Hey, this:

For hybrid mode we do get default locale using preferedLanguages as you mentioned

Is applied only if there are more than 1 preferedLanguages selected. For single one it can be still evaluated as
localeName = [NSString stringWithFormat:@"%@-%@", currentLocale.languageCode, currentLocale.countryCode];

@mkhamoyan
Copy link
Contributor

@sowacx, The check NSLocale.preferredLanguages.count > 0 is verifying the presence of any preferred languages. According to the documentation, the primary language of the device will always be included in the preferred languages list.

@matouskozak
Copy link
Member

matouskozak commented Jul 4, 2024

Fixed in #102748, should be part of next servicing release (8.0.8).

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Jul 4, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests