This function returns an array of all the installed cultures in the App_GlobalResources folder - change search path according to your needs.
For the invariant culture it returns "auto".
public static string[] GetInstalledCultures()
{
List<string> cultures = new List<string>();
foreach (string file in Directory.GetFiles(HttpContext.Current.Server.MapPath("/App_GlobalResources"), \\Change folder to search in if needed.
"*.resx", SearchOption.TopDirectoryOnly))
{
string name = file.Split('\\').Last();
name = name.Split('.')[1];
cultures.Add(name != "resx" ? name : "auto"); \\Change "auto" to something else like "en-US" if needed.
}
return cultures.ToArray();
}
You could also use this one for more functionality getting the full CultureInfo instances:
public static CultureInfo[] GetInstalledCultures()
{
List<CultureInfo> cultures = new List<CultureInfo>();
foreach (string file in Directory.GetFiles(HttpContext.Current.Server.MapPath("/App_GlobalResources"), "*.resx", SearchOption.TopDirectoryOnly))
{
string name = file.Split('\\').Last();
name = name.Split('.')[1];
string culture = name != "resx" ? name : "en-US";
cultures.Add(new CultureInfo(culture));
}
return cultures.ToArray();
}