Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed
- [SIL.WritingSystems] Fix IetfLanguageTag.GetGeneralCode to handle cases when zh-CN or zh-TW is a prefix and not the whole string.
- [SIL.WritingSystems] More fixes to consistently use 繁体中文 and 简体中文 for Traditional and Simplified Chinese native language names, and Chinese (Traditional) and Chinese (Simplified) for their English names.
- [SIL.Windows.Forms] Prevent BetterLabel from responding to OnTextChanged when it has been disposed.

### Changed
Expand Down
56 changes: 26 additions & 30 deletions SIL.WritingSystems/IetfLanguageTag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,21 +1304,24 @@ public static string GetLocalizedLanguageName(string languageTag, string uiLangu
var generalCode = GetGeneralCode(languageTag);
var uiLanguageCode = GetLanguagePart(uiLanguageTag);

if (generalCode == ChineseSimplifiedTag && uiLanguageCode == "en")
if (generalCode == ChineseSimplifiedTag)
{
// We also use this as the "English Subtitle" in GetNativeLanguageNameWithEnglishSubtitle. Not sure if
// it really matters here, but the ICU-supplied name (e.g., used on Linux), and the EnglishName and
// We also use this as the "English Subtitle" in GetNativeLanguageNameWithEnglishSubtitle.
// The ICU-supplied name (e.g., used on Linux), and the EnglishName and
// DisplayName supplied via the Windows CultureInfo are all subtly different in
// unhelpful ways:
// ICU: Chinese (China)
// DisplayName: Chinese (Simplified, PRC) or Chinese (Simplified, Mainland China) or Chinese (China)
// EnglishName: Chinese (Simplified, China) or Chinese (Simplified, Mainland China) or Chinese (China)

return kSimplifiedChineseNameInEnglish;
if (uiLanguageCode == "en")
return kSimplifiedChineseNameInEnglish;
return kSimplifiedChineseAutonym;
}
else if (generalCode == ChineseTraditionalTag && uiLanguageCode == "en")
if (generalCode == ChineseTraditionalTag)
{
return kTraditionalChineseNameInEnglish;
if (uiLanguageCode == "en")
return kTraditionalChineseNameInEnglish;
return kTraditionalChineseAutonym;
}

// Starting some time around Sept 2025, Windows started returning the "fa" culture
Expand Down Expand Up @@ -1360,11 +1363,7 @@ public static string GetLocalizedLanguageName(string languageTag, string uiLangu
langName = ci.DisplayName;
if (uiLanguageCode != "en")
{
if (
langName == ci.EnglishName
|| generalCode == ChineseSimplifiedTag
|| generalCode == ChineseTraditionalTag
)
if (langName == ci.EnglishName)
langName = FixBotchedNativeName(ci.NativeName);
}
if (IsNullOrWhiteSpace(langName))
Expand Down Expand Up @@ -1424,6 +1423,14 @@ public static string GetNativeLanguageNameWithEnglishSubtitle(string code)
// englishNameSuffix is always an empty string if we don't need it.
string englishNameSuffix = Empty;

if (generalCode == ChineseSimplifiedTag)
{
return $"{kSimplifiedChineseAutonym} ({kSimplifiedChineseNameInEnglish})";
}
if (generalCode == ChineseTraditionalTag)
{
return $"{kTraditionalChineseAutonym} ({kTraditionalChineseNameInEnglish})";
}
// Starting some time around Sept 2025, Windows started returning the "fa" culture
// for CultureInfo.GetCultureInfo("prs"). We actually want to return Dari in that case.
if (generalCode == "prs")
Expand All @@ -1437,16 +1444,13 @@ public static string GetNativeLanguageNameWithEnglishSubtitle(string code)
if (IsNullOrWhiteSpace(nativeName))
nativeName = code;

if (ci.Name != ChineseSimplifiedTag && ci.Name != ChineseTraditionalTag)
{
// Remove any country (or script?) names.
var idxCountry = englishNameSuffix.LastIndexOf(" (", StringComparison.Ordinal);
if (englishNameSuffix.Length > 0 && idxCountry > 0)
englishNameSuffix = englishNameSuffix.Substring(0, idxCountry) + ")";
idxCountry = nativeName.IndexOf(" (", StringComparison.Ordinal);
if (idxCountry > 0)
nativeName = nativeName.Substring(0, idxCountry);
}
// Remove any country (or script?) names.
var idxCountry = englishNameSuffix.LastIndexOf(" (", StringComparison.Ordinal);
if (englishNameSuffix.Length > 0 && idxCountry > 0)
englishNameSuffix = englishNameSuffix.Substring(0, idxCountry) + ")";
idxCountry = nativeName.IndexOf(" (", StringComparison.Ordinal);
if (idxCountry > 0)
nativeName = nativeName.Substring(0, idxCountry);
langName = nativeName + englishNameSuffix;
if (!ci.IsUnknownCulture())
{
Expand Down Expand Up @@ -1594,14 +1598,6 @@ private static string FixBotchedNativeName(string name)
// Incorrect capitalization on older Windows OS versions.
case "Português":
return "português";
case "中文(中国)":
case "中文(中国)":
return kSimplifiedChineseAutonym;
case "中文(台灣)":
case "中文(台灣)":
case "中文(台湾)":
case "中文(台湾)":
return kTraditionalChineseAutonym;
default:
return name;
}
Expand Down
Loading