Generalized the culture-to-flag map
This commit is contained in:
@@ -54,6 +54,36 @@ namespace Swarmops.Logic.Support
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public static string FlagFileFromCultureId(string cultureId)
|
||||
{
|
||||
cultureId = cultureId.ToLowerInvariant();
|
||||
|
||||
Dictionary<string, string> nonStandardFlagNames = new Dictionary<string, string>();
|
||||
nonStandardFlagNames["en"] = "uk"; // Use UK flag for US English
|
||||
nonStandardFlagNames["ar"] = "Arabic"; // Arabic doesn't have a country flag per se
|
||||
nonStandardFlagNames["fil"] = "ph"; // Philippines / Filipino
|
||||
nonStandardFlagNames["el"] = "gr"; // Greece / Ελληνικά
|
||||
nonStandardFlagNames["yo"] = "ng"; // Nigeria / Yoruba
|
||||
nonStandardFlagNames["zh"] = "ch"; // China / Chinese
|
||||
|
||||
string cultureFirstPart = cultureId.Split('-')[0];
|
||||
|
||||
if (cultureId == "af-za") // Translation pseudocode
|
||||
{
|
||||
return "/Images/Flags/txl-64px.png";
|
||||
}
|
||||
else if (nonStandardFlagNames.ContainsKey(cultureFirstPart))
|
||||
{
|
||||
return "/Images/Flags/" + nonStandardFlagNames[cultureFirstPart] + "-64px.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "/Images/Flags/" + cultureId.Substring(3, 2) + "-64px.png";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ReSharper disable once InconsistentNaming -- IPAddress is the canonical writing
|
||||
public static string GetRemoteIPAddressChain()
|
||||
{
|
||||
|
||||
@@ -210,24 +210,9 @@ namespace Swarmops.Frontend
|
||||
Response.Cookies.Add (cookieCulture);
|
||||
}
|
||||
|
||||
string flagName = "uk";
|
||||
|
||||
if (!cultureStringLower.StartsWith ("en") && cultureString.Length > 3)
|
||||
if (cultureStringLower == "af-za") // "South African Afrikaans", a special placeholder for localization code
|
||||
{
|
||||
flagName = cultureStringLower.Substring (3);
|
||||
}
|
||||
|
||||
if (cultureStringLower.StartsWith ("ar"))
|
||||
{
|
||||
flagName = "Arabic";
|
||||
}
|
||||
else if (cultureStringLower == "fil-latn" || cultureStringLower == "fil-ph")
|
||||
{
|
||||
flagName = "ph"; // Filipino culture
|
||||
}
|
||||
else if (cultureStringLower == "af-za") // "South African Afrikaans", a special placeholder for localization code
|
||||
{
|
||||
flagName = "txl";
|
||||
InitTranslation();
|
||||
}
|
||||
else
|
||||
@@ -235,7 +220,7 @@ namespace Swarmops.Frontend
|
||||
this.LiteralCrowdinScript.Text = string.Empty;
|
||||
}
|
||||
|
||||
this.ImageCultureIndicator.ImageUrl = "~/Images/Flags/" + flagName + "-24px.png";
|
||||
this.ImageCultureIndicator.ImageUrl = SupportFunctions.FlagFileFromCultureId(cultureString);
|
||||
|
||||
this.LinkLogout.Text = Global.CurrentUserInfo_Logout;
|
||||
this.LabelPreferences.Text = Global.CurrentUserInfo_Preferences;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Frontend.Pages.v5.User
|
||||
{
|
||||
@@ -33,17 +34,8 @@ namespace Swarmops.Frontend.Pages.v5.User
|
||||
{
|
||||
string[] availableCultures = {"ar-AE", "de-DE", "el", "es-ES", "fr-FR", "fil-Latn", "it-IT", "nl-NL", "pl-PL", "pt-PT", "ru-RU", "tr-TR", "sv-SE", "yo-Latn", "zh-CHS" };
|
||||
|
||||
Dictionary<string,string> nonStandardFlagNames = new Dictionary<string, string>();
|
||||
nonStandardFlagNames["en"] = "uk"; // Use UK flag for US English
|
||||
nonStandardFlagNames["ar"] = "Arabic"; // Arabic doesn't have a country flag per se
|
||||
nonStandardFlagNames["fil"] = "ph"; // Philippines / Filipino
|
||||
nonStandardFlagNames["el"] = "gr"; // Greece / Ελληνικά
|
||||
nonStandardFlagNames["yo"] = "ng"; // Nigeria / Yoruba
|
||||
nonStandardFlagNames["zh"] = "ch"; // China / Chinese
|
||||
|
||||
|
||||
Array.Sort (availableCultures);
|
||||
// sort by locale string, and that's ok, that happens to give the same result as sorting on country name
|
||||
// sort by locale string, and that's ok, that happens to give the same result as sorting on language native name, which is the desired outcome
|
||||
|
||||
List<LanguageParameters> availableLanguages = new List<LanguageParameters>();
|
||||
foreach (string cultureId in availableCultures)
|
||||
@@ -58,16 +50,8 @@ namespace Swarmops.Frontend.Pages.v5.User
|
||||
// Do not display country, just the language name
|
||||
newLanguage.DisplayName = newLanguage.DisplayName.Split (' ')[0];
|
||||
|
||||
string cultureFirstPart = cultureId.Split('-')[0];
|
||||
newLanguage.IconUrl = SupportFunctions.FlagFileFromCultureId(cultureId);
|
||||
|
||||
if (nonStandardFlagNames.ContainsKey(cultureFirstPart))
|
||||
{
|
||||
newLanguage.IconUrl = "/Images/Flags/" + nonStandardFlagNames[cultureFirstPart] + "-64px.png";
|
||||
}
|
||||
else
|
||||
{
|
||||
newLanguage.IconUrl = "/Images/Flags/" + cultureId.Substring(3, 2).ToLowerInvariant() + "-64px.png";
|
||||
}
|
||||
if (culture.TextInfo.IsRightToLeft)
|
||||
{
|
||||
newLanguage.Rtl = "rtl";
|
||||
|
||||
Reference in New Issue
Block a user