dotnet/runtime

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

Open

#106,560 创建于 2024年8月16日

在 GitHub 查看
 (11 评论) (1 反应) (0 负责人)C# (5,445 fork)batch import
area-System.Globalizationgood first issueos-android

仓库指标

Star
 (17,886 star)
PR 合并指标
 (平均合并 12天 11小时) (30 天内合并 661 个 PR)

描述

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

贡献者指南