dotnet / runtime

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

Android - With set Turkish locale "i".ToUpper() is giving 'I" instead of 'İ' #106560

Open sowacx opened 2 months ago

sowacx commented 2 months ago

Description

Hello,

There is long story with Turkish 'ı' and 'i'. Many details can be found here: http://www.i18nguy.com/unicode/turkish-i18n.html Long story short - With Turkish locale ToUpper should transform text in this way: i -> İ (dotted i) ı -> I (dottless ı)

For investigation I am using phrase 'Anlıyorum bilgi edinin iİ'. Transformation TpUpper should give result 'ANLIYORUM BİLGİ EDİNİN İİ', but MAUI on Android platform is 'ANLIYORUM BILGI EDININ Iİ'

It's working fine with plain .NET8 console app, proof: https://dotnetfiddle.net/fIV4eQ

I found two issues reported at dotnet / runtime project that are describing that issue. Both were closed with comments that were pointing that root cause is Android ICU and dotnet familly can not do much about it. https://github.com/dotnet/runtime/issues/77689 https://github.com/dotnet/runtime/issues/102622

But I started to dig a bit deeper. I found out that when I run Kotlin project with Android studio everything is fine. I forked some github project that is setting Locale to specific language. When I set 'en' it is giving me 'ANLIYORUM BILGI EDININ Iİ', but then setting 'tr' locale produces 'ANLIYORUM BİLGİ EDİNİN İİ'. Everything is proper at here. So why it's not with MAUI Android? Repository for my forked Kotlin project: https://github.com/sowacx/WizardOfLocale-maui-investigation image

Then I tried to call setLocale the same way as in Kotlin App. That is possible by overriding MainActivity method AttachBaseContext. Code looks like that:

using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.Content.Res;
using Android.OS;

namespace TurkishSandbox;

[Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTop,
    ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode |
                           ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
public class MainActivity : MauiAppCompatActivity
{
    protected override void AttachBaseContext(Context baseContext)
    {
        Java.Util.Locale locale = new Java.Util.Locale("tr");
        Java.Util.Locale.Default = locale;

        Resources res = baseContext.Resources;
        Configuration config = new Configuration(res.Configuration);
        if ((int)Build.VERSION.SdkInt >= 17)
        {
            config.SetLocale(locale);
            config.SetLayoutDirection(locale);
            baseContext = baseContext.CreateConfigurationContext(config);
        }
        else
        {
            config.Locale = locale;
            res.UpdateConfiguration(config, res.DisplayMetrics);
        }

        base.AttachBaseContext(baseContext);
    }
}

Additionally I set up Cultures to 'tr-TR' at MauiApplication c'tor. But that all did not fix problem. image

My MAUI project to reproduce: https://github.com/sowacx/maui-turkish-locale-issue

Steps to Reproduce

  1. Create MAUI Boilerplate app.
  2. Place Label at MainPage.xaml <Label Text="Anlıyorum bilgi edinin iİ" TextTransform="Uppercase" Style="{StaticResource Headline}" SemanticProperties.HeadingLevel="Level1" />
  3. Explicitly set up 'tr-TR' culture or change Android phone language to Turkish
  4. Run
  5. New label text should be 'ANLIYORUM BİLGİ EDİNİN İİ', but it is 'ANLIYORUM BILGI EDININ I'

Link to public reproduction project repository

https://github.com/sowacx/maui-turkish-locale-issue

Version with bug

8.0.40 SR5

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

Unfortunately no

Relevant log output

No response

github-actions[bot] commented 2 months ago

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!

Closed similar issues:

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

dotnet-policy-service[bot] commented 2 months ago

Tagging subscribers to 'arch-android': @vitek-karas, @simonrozsival, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 2 months ago

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

tarekgh commented 2 months ago

CC @ilonatommy @matouskozak

matouskozak commented 2 months ago

@sowacx thank you for this issue and the comparison with Kotlin. This is something we need to investigate and reconsider if there is a possibility for us to get the necessary culture information from Android ICU.