Fix language selector throwing a exception, use native name for Taiwan (#1634)

The language selector has only been showing language codes and not the
actual language names since  dd0159ae5a
because "tw" (Taiwan Mandarin) was added and it's not supported by
CultureInfo.

This adds a specific check like the language code to work around this
and stop throwing exceptions. Also converts to a switch so it looks a
bit nicer.
This commit is contained in:
Joshua Goins 2024-02-07 18:33:35 +00:00 committed by GitHub
parent 65265b678e
commit 1d32e8fe45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,17 +31,20 @@ public sealed class LanguageChooserSettingsEntry : SettingsEntry
try try
{ {
var locLanguagesList = new List<string>(); var locLanguagesList = new List<string>();
string locLanguage;
foreach (var language in this.languages) foreach (var language in this.languages)
{ {
if (language != "ko") switch (language)
{ {
locLanguage = CultureInfo.GetCultureInfo(language).NativeName; case "ko":
locLanguagesList.Add(char.ToUpper(locLanguage[0]) + locLanguage[1..]); locLanguagesList.Add("Korean");
} break;
else case "tw":
{ locLanguagesList.Add("中華民國國語");
locLanguagesList.Add("Korean"); break;
default:
string locLanguage = CultureInfo.GetCultureInfo(language).NativeName;
locLanguagesList.Add(char.ToUpper(locLanguage[0]) + locLanguage[1..]);
break;
} }
} }