Skip to content

Instantly share code, notes, and snippets.

@elizabeth-young
Last active January 6, 2016 08:05
Show Gist options
  • Save elizabeth-young/5670609 to your computer and use it in GitHub Desktop.
Save elizabeth-young/5670609 to your computer and use it in GitHub Desktop.
Determines culture to be used
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