Get CultureInfo by Culture English Title

Can I get CultureInfo culture of the English name ?

Imagine what we have: Danish, English, Spanish, etc.

Thanks!

+4
source share
3 answers
 var names = CultureInfo.GetCultures(CultureTypes.AllCultures).ToLookup(x => x.EnglishName); names["English"].FirstOrDefault(); 
+7
source
 var EnglishCulture = CultureInfo.GetCultures(CultureTypes.AllCultures) .Where(r => r.EnglishName == "English"); 

Or if you need FirstOrDefault

 var EnglishCulture = CultureInfo.GetCultures(CultureTypes.AllCultures) .FirstOrDefault(r=> r.EnglishName == "English"); 
+8
source

There is no built-in method to get the culture by the English name, so you can write one:

 public static CultureInfo getCultureByEnglishName(String englishName) { // create an array of CultureInfo to hold all the cultures found, // these include the users local culture, and all the // cultures installed with the .Net Framework CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures); // get culture by it english name var culture = cultures.FirstOrDefault(c => c.EnglishName.Equals(englishName, StringComparison.InvariantCultureIgnoreCase)); return culture; } 

Here's a demo : http://ideone.com/KX4U8l

+3
source

Source: https://habr.com/ru/post/1445485/


All Articles