Get language codes from a country code in C#
Given a country code – i.e. BE (Belgium), you might want to know the most commonly spoken languages in that country – i.e FR and NL (French and Dutch), here’s some code to do that in C#, without a database lookup.
private static IEnumerable<string> GetLanguagesSpokenInCountry(string country)
{
var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
var languagesSpoken = allCultures.Where(c =>
{
if (c.IsNeutralCulture) return false;
if (c.LCID == 0x7F) return false; // Ignore Invariant culture
var region = new RegionInfo(c.LCID);
return region.TwoLetterISORegionName == country;
}).Select(c => c.TwoLetterISOLanguageName.ToUpper()).ToList();
return languagesSpoken;
}
You might be surprised that India (IN) returns 19 languages! – on my PC.