Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private static string GetLanguageDisplayName(string cultureName)
return new CultureInfo(cultureName)._cultureData.GetLocaleInfo(cultureName, LocaleStringData.LocalizedDisplayName);
}

private static string? GetRegionDisplayName(string? isoCountryCode)
private static string? GetRegionDisplayName()
{
// use the fallback which is to return NativeName
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private string GetLanguageDisplayName(string cultureName)
}
}

private string GetRegionDisplayName(string isoCountryCode)
private string GetRegionDisplayName()
{
// If the current UI culture matching the OS UI language, we'll get the display name from the OS.
// otherwise, we use the native name as we don't carry resources for the region display names anyway.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -795,17 +795,18 @@ internal string DisplayName
{
get
{
if (_sLocalizedDisplayName == null)
string? localizedDisplayName = _sLocalizedDisplayName;
if (localizedDisplayName == null)
{
if (IsSupplementalCustomCulture)
{
if (IsNeutralCulture)
{
_sLocalizedDisplayName = NativeLanguageName;
localizedDisplayName = NativeLanguageName;
}
else
{
_sLocalizedDisplayName = NativeName;
localizedDisplayName = NativeName;
}
}
else
Expand All @@ -817,29 +818,30 @@ internal string DisplayName

if (Name.Equals(ZH_CHT, StringComparison.OrdinalIgnoreCase))
{
_sLocalizedDisplayName = GetLanguageDisplayName("zh-Hant");
localizedDisplayName = GetLanguageDisplayName("zh-Hant");
}
else if (Name.Equals(ZH_CHS, StringComparison.OrdinalIgnoreCase))
{
_sLocalizedDisplayName = GetLanguageDisplayName("zh-Hans");
localizedDisplayName = GetLanguageDisplayName("zh-Hans");
}
else
{
_sLocalizedDisplayName = GetLanguageDisplayName(Name);
localizedDisplayName = GetLanguageDisplayName(Name);
}
}
catch
{
// do nothing
}
}

// If it hasn't been found (Windows 8 and up), fallback to the system
if (string.IsNullOrEmpty(_sLocalizedDisplayName))
if (string.IsNullOrEmpty(localizedDisplayName))
{
// If its neutral use the language name
if (IsNeutralCulture)
{
_sLocalizedDisplayName = LocalizedLanguageName;
localizedDisplayName = LocalizedLanguageName;
}
else
{
Expand All @@ -851,17 +853,19 @@ internal string DisplayName
((ci = CultureInfo.GetUserDefaultCulture()) != null) &&
!CultureInfo.DefaultThreadCurrentUICulture.Name.Equals(ci.Name))
{
_sLocalizedDisplayName = NativeName;
localizedDisplayName = NativeName;
}
else
{
_sLocalizedDisplayName = GetLocaleInfo(LocaleStringData.LocalizedDisplayName);
localizedDisplayName = GetLocaleInfo(LocaleStringData.LocalizedDisplayName);
}
}
}

_sLocalizedDisplayName = localizedDisplayName;
}

return _sLocalizedDisplayName;
return localizedDisplayName;
}
}

Expand All @@ -872,35 +876,36 @@ internal string EnglishName
{
get
{
if (_sEnglishDisplayName == null)
string? englishDisplayName = _sEnglishDisplayName;
if (englishDisplayName == null)
{
// If its neutral use the language name
if (IsNeutralCulture)
{
_sEnglishDisplayName = EnglishLanguageName;
englishDisplayName = EnglishLanguageName;
// differentiate the legacy display names
switch (_sName)
{
case "zh-CHS":
case "zh-CHT":
_sEnglishDisplayName += " Legacy";
englishDisplayName += " Legacy";
break;
}
}
else
{
_sEnglishDisplayName = GetLocaleInfo(LocaleStringData.EnglishDisplayName);
englishDisplayName = GetLocaleInfo(LocaleStringData.EnglishDisplayName);

// if it isn't found build one:
if (string.IsNullOrEmpty(_sEnglishDisplayName))
if (string.IsNullOrEmpty(englishDisplayName))
{
// Our existing names mostly look like:
// "English" + "United States" -> "English (United States)"
// "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)"
if (EnglishLanguageName[^1] == ')')
{
// "Azeri (Latin)" + "Azerbaijan" -> "Azeri (Latin, Azerbaijan)"
_sEnglishDisplayName = string.Concat(
englishDisplayName = string.Concat(
EnglishLanguageName.AsSpan(0, _sEnglishLanguage!.Length - 1),
", ",
EnglishCountryName,
Expand All @@ -909,12 +914,15 @@ internal string EnglishName
else
{
// "English" + "United States" -> "English (United States)"
_sEnglishDisplayName = EnglishLanguageName + " (" + EnglishCountryName + ")";
englishDisplayName = EnglishLanguageName + " (" + EnglishCountryName + ")";
}
}
}

_sEnglishDisplayName = englishDisplayName;
}
return _sEnglishDisplayName;

return englishDisplayName;
}
}

Expand All @@ -925,36 +933,40 @@ internal string NativeName
{
get
{
if (_sNativeDisplayName == null)
string? nativeDisplayName = _sNativeDisplayName;
if (nativeDisplayName == null)
{
// If its neutral use the language name
if (IsNeutralCulture)
{
_sNativeDisplayName = NativeLanguageName;
nativeDisplayName = NativeLanguageName;
// differentiate the legacy display names
switch (_sName)
{
case "zh-CHS":
_sNativeDisplayName += " \u65E7\u7248";
nativeDisplayName += " \u65E7\u7248";
break;
case "zh-CHT":
_sNativeDisplayName += " \u820A\u7248";
nativeDisplayName += " \u820A\u7248";
break;
}
}
else
{
_sNativeDisplayName = GetLocaleInfo(LocaleStringData.NativeDisplayName);
nativeDisplayName = GetLocaleInfo(LocaleStringData.NativeDisplayName);

// if it isn't found build one:
if (string.IsNullOrEmpty(_sNativeDisplayName))
if (string.IsNullOrEmpty(nativeDisplayName))
{
// These should primarily be "Deutsch (Deutschland)" type names
_sNativeDisplayName = NativeLanguageName + " (" + NativeCountryName + ")";
nativeDisplayName = NativeLanguageName + " (" + NativeCountryName + ")";
}
}

_sNativeDisplayName = nativeDisplayName;
}
return _sNativeDisplayName;

return nativeDisplayName;
}
}

Expand Down Expand Up @@ -1050,23 +1062,23 @@ internal string LocalizedCountryName
{
get
{
if (_sLocalizedCountry == null)
string? localizedCountry = _sLocalizedCountry;
if (localizedCountry == null)
{
try
{
_sLocalizedCountry = GetRegionDisplayName(TwoLetterISOCountryName);
localizedCountry = GetRegionDisplayName();
}
catch
{
// do nothing. we'll fallback
}

if (_sLocalizedCountry == null)
{
_sLocalizedCountry = NativeCountryName;
}
localizedCountry ??= NativeCountryName;
_sLocalizedCountry = localizedCountry;
}
return _sLocalizedCountry;

return localizedCountry;
}
}

Expand Down