From 8fd5b77003deca5421670d50d0257fb3afd415bc Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Mon, 26 Jul 2021 12:29:39 -0700 Subject: [PATCH 1/5] Fix Neutral Culture Names --- .../tests/CultureInfo/CultureInfoEnglishName.cs | 4 ++++ .../src/System/Globalization/CultureData.cs | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index ad2c2c9eda57b4..1c3dac393f56c3 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -23,6 +23,10 @@ public static IEnumerable EnglishName_TestData() // Mobile / Browser ICU doesn't contain CultureInfo.EnglishName yield return new object[] { "en-US", "en (US)" }; yield return new object[] { "fr-FR", "fr (FR)" }; + yield return new object[] { "zh-Hant", "Chinese (Traditional)" }; + yield return new object[] { "zh-Hans", "Chinese (Simplified)" }; + yield return new object[] { "uz-Arab", "Uzbek (Arabic)" }; + yield return new object[] { "uz-Cyrl", "Uzbek (Cyrillic)" }; } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs index c952e4cb0cdddd..43e0cfe87fc12a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs @@ -969,7 +969,12 @@ internal string EnglishName // If its neutral use the language name if (IsNeutralCulture) { - englishDisplayName = EnglishLanguageName; + englishDisplayName = GetLocaleInfoCore(LocaleStringData.EnglishDisplayName); + if (string.IsNullOrEmpty(englishDisplayName)) + { + englishDisplayName = EnglishLanguageName; + } + // differentiate the legacy display names switch (_sName) { @@ -1026,7 +1031,12 @@ internal string NativeName // If its neutral use the language name if (IsNeutralCulture) { - nativeDisplayName = NativeLanguageName; + nativeDisplayName = GetLocaleInfoCore(LocaleStringData.NativeDisplayName); + if (string.IsNullOrEmpty(nativeDisplayName)) + { + nativeDisplayName = NativeLanguageName; + } + // differentiate the legacy display names switch (_sName) { From 6daac6987356ac59b265c729a737389f54534789 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Mon, 26 Jul 2021 15:36:58 -0700 Subject: [PATCH 2/5] Fix the test --- .../tests/CultureInfo/CultureInfoEnglishName.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 1c3dac393f56c3..9a2a1f5f70e7cf 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -17,16 +17,16 @@ public static IEnumerable EnglishName_TestData() { yield return new object[] { "en-US", "English (United States)" }; yield return new object[] { "fr-FR", "French (France)" }; + yield return new object[] { "zh-Hant", "Chinese (Traditional)" }; + yield return new object[] { "zh-Hans", "Chinese (Simplified)" }; + yield return new object[] { "uz-Arab", "Uzbek (Arabic)" }; + yield return new object[] { "uz-Cyrl", "Uzbek (Cyrillic)" }; } else { // Mobile / Browser ICU doesn't contain CultureInfo.EnglishName yield return new object[] { "en-US", "en (US)" }; yield return new object[] { "fr-FR", "fr (FR)" }; - yield return new object[] { "zh-Hant", "Chinese (Traditional)" }; - yield return new object[] { "zh-Hans", "Chinese (Simplified)" }; - yield return new object[] { "uz-Arab", "Uzbek (Arabic)" }; - yield return new object[] { "uz-Cyrl", "Uzbek (Cyrillic)" }; } } From 9982d69eb11b0ea3c7bd786fed12b0ee33275ea3 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Mon, 26 Jul 2021 17:17:05 -0700 Subject: [PATCH 3/5] Fix the test --- .../tests/CultureInfo/CultureInfoEnglishName.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 9a2a1f5f70e7cf..7c10bc3fa08748 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -19,7 +19,6 @@ public static IEnumerable EnglishName_TestData() yield return new object[] { "fr-FR", "French (France)" }; yield return new object[] { "zh-Hant", "Chinese (Traditional)" }; yield return new object[] { "zh-Hans", "Chinese (Simplified)" }; - yield return new object[] { "uz-Arab", "Uzbek (Arabic)" }; yield return new object[] { "uz-Cyrl", "Uzbek (Cyrillic)" }; } else From 9e1be3bca206f817ba6fa2ee22e42638c93d71ef Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Tue, 27 Jul 2021 09:51:22 -0700 Subject: [PATCH 4/5] Fix failing tests on Mac --- .../CultureInfo/CultureInfoEnglishName.cs | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 7c10bc3fa08748..9b67fb9d4303c5 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -8,17 +8,17 @@ namespace System.Globalization.Tests { public class CultureInfoEnglishName { + // Android has its own ICU, which doesn't 100% map to UsingLimitedCultures + public static bool SupportFullGlobalizationData => PlatformDetection.IsNotUsingLimitedCultures || PlatformDetection.IsAndroid; + public static IEnumerable EnglishName_TestData() { yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.EnglishName }; - // Android has its own ICU, which doesn't 100% map to UsingLimitedCultures - if (PlatformDetection.IsNotUsingLimitedCultures || PlatformDetection.IsAndroid) + if (SupportFullGlobalizationData) { yield return new object[] { "en-US", "English (United States)" }; yield return new object[] { "fr-FR", "French (France)" }; - yield return new object[] { "zh-Hant", "Chinese (Traditional)" }; - yield return new object[] { "zh-Hans", "Chinese (Simplified)" }; yield return new object[] { "uz-Cyrl", "Uzbek (Cyrillic)" }; } else @@ -36,5 +36,17 @@ public void EnglishName(string name, string expected) CultureInfo myTestCulture = new CultureInfo(name); Assert.Equal(expected, myTestCulture.EnglishName); } + + [ConditionalFact(nameof(SupportFullGlobalizationData))] + public void ChineseNeutralEnglishName() + { + CultureInfo ci = new CultureInfo("zh-Hans"); + Assert.True(ci.EnglishName == "Chinese (Simplified)" || ci.EnglishName == "Chinese, Simplified", + $"'{ci.EnglishName}' not equal to `Chinese (Simplified)` nor `Chinese, Simplified`"); + + ci = new CultureInfo("zh-HanT"); + Assert.True(ci.EnglishName == "Chinese (Traditional)" || ci.EnglishName == "Chinese, Simplified", + $"'{ci.EnglishName}' not equal to `Chinese (Traditional)` nor `Chinese, Traditional`"); + } } } From 08398f3e63a86e9fd59da52a5c796751b82eb1f7 Mon Sep 17 00:00:00 2001 From: Tarek Mahmoud Sayed Date: Tue, 27 Jul 2021 11:45:55 -0700 Subject: [PATCH 5/5] Fix typo in the test --- .../tests/CultureInfo/CultureInfoEnglishName.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 9b67fb9d4303c5..67a19e61401164 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -45,7 +45,7 @@ public void ChineseNeutralEnglishName() $"'{ci.EnglishName}' not equal to `Chinese (Simplified)` nor `Chinese, Simplified`"); ci = new CultureInfo("zh-HanT"); - Assert.True(ci.EnglishName == "Chinese (Traditional)" || ci.EnglishName == "Chinese, Simplified", + Assert.True(ci.EnglishName == "Chinese (Traditional)" || ci.EnglishName == "Chinese, Traditional", $"'{ci.EnglishName}' not equal to `Chinese (Traditional)` nor `Chinese, Traditional`"); } }