dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.14k stars 4.71k forks source link

iOS UI Culture for Localisation #108753

Open IeuanWalker opened 1 week ago

IeuanWalker commented 1 week ago

Description

When the app launches the SetCulture method is called, set the apps culture to what the user has saved. Image

This works completely fine on Android, but on iOS StringFormat in the xaml doesn't use the set culture, and stays as english - Image

I've also tried doing the StringFormat in the model, and it also doesn't work - Image

Even setting the culture manually doesn't work - Image


It all worked fine in Xamarin.Forms, and it is a valid .NET Culture - https://dotnetfiddle.net/lyJP18 Image

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.90 SR9

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

No response

Did you find any workaround?

No, unless this is fixed, the only way I can see to work around it is to add a property to the API and perform the translation there.

Relevant log output

No response

bhavanesh2001 commented 1 week ago

@IeuanWalker did you defined all supported languages in info.plist ? Refer to the documentation

IeuanWalker commented 1 week ago

@bhavanesh2001 I wasnt aware of that, must be something new in MAUI.

I have tried added -

<key>CFBundleLocalizations</key>
<array>
    <string>cy</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>

and

<key>CFBundleLocalizations</key>
<array>
    <string>cy-GB</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>

But still doesn't work

baaaaif commented 1 week ago

have a look at https://github.com/dotnet/runtime/issues/76596 maybe it is the same case for cy-GB - it is not in https://github.com/dotnet/icu/blob/dotnet/main/icu-filters/icudt_mobile.json

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @ivanpovazan, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 1 week ago

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

ivanpovazan commented 1 week ago

/cc: @matouskozak @mkhamoyan

matouskozak commented 1 week ago

@IeuanWalker The reason is likely the missing culture in the ICU we use for mobile as mentioned by @baaaaif. We try to make a trade-off between supporting full ICU and resulting app size on iOS, so we only included the most common culture names.

I just checked, and it works as expected with .NET 9 RC1. That is because, in .NET 9, we switched from using our own ICU to using the Apple ICU found on devices.

IeuanWalker commented 1 week ago

thanks @matouskozak, so in .NET 9 it should just work?

or would I still need to add this to the info.plist?

<key>CFBundleLocalizations</key>
<array>
    <string>cy</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
matouskozak commented 1 week ago

thanks @matouskozak, so in .NET 9 it should just work?

or would I still need to add this to the info.plist?

CFBundleLocalizations cy CFBundleDevelopmentRegion en

Yes, the code that you sent

DateTime now = DateTime.Now;

Console.WriteLine("English: " +  now.ToString("dddd, dd MMMM", new CultureInfo("en-GB")));
Console.WriteLine("Welsh: " +  now.ToString("dddd, dd MMMM", new CultureInfo("cy-GB")));

should work as is.

I believe that https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/localization?view=net-maui-8.0#ios-and-mac-catalyst is necessary if you plan to use localized resources.