I have a list of languages in english form:
German
English
French
...
I want to get:
DE
EN
FR
how can I do this?
Sounds like you just need to take the complete list of neutral (language-only) cultures, join that with your English names list, and then project that:
var languageCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
var twoLetterNames = from culture in languageCultures
join englishName in englishNames
on culture.EnglishName equals englishName
select culture.TwoLetterISOLanguageName;
If you do this regularly, you might want to build a Dictionary<string, string>
:
var cultureByLanguage = languageCultures.ToDictionary(x => x.EnglishName);
or:
var twoLetterIsoByLanguage = languageCultures.ToDictionary
(x => x.EnglishName,
x => TwoLetterISOLanguageName);
See more on this question at Stackoverflow