Last active
January 6, 2016 08:05
-
-
Save elizabeth-young/5670609 to your computer and use it in GitHub Desktop.
Determines culture to be used
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocalisationHelper | |
{ | |
public static List<string> Cultures | |
{ | |
get { return new[] {"en-GB", "es"}.ToList(); } | |
} | |
public static string DefaultCulture | |
{ | |
get { return Cultures[0]; } | |
} | |
/// <summary> | |
/// Gets a similar culture to the one passed (e.g. if en-US passed, returns nearest en-GB), | |
/// or returns default | |
/// </summary> | |
public static string GetCulture(string culture) | |
{ | |
string result = null; | |
if (Cultures.Contains(culture)) | |
{ | |
return culture; | |
} | |
Cultures.ToList().ForEach(c => | |
{ | |
if (c.Substring(0, 2) == culture.Substring(0, 2)) | |
{ | |
result = c; | |
} | |
}); | |
if (string.IsNullOrEmpty(result)) | |
{ | |
result = DefaultCulture; | |
} | |
return result; | |
} | |
public static bool CultureImplemented(string culture) | |
{ | |
return Cultures.ToList().Contains(culture); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment