简体   繁体   中英

C# - How can I get the language name from the language code?

I'm looking for a way to get the language name from the language code.

en -> English
zh -> Chinese
jp -> Japanese
fr -> French
de -> German

etc...

Console.WriteLine(new CultureInfo("en").DisplayName);

Note that DisplayName will format the name for the currently set language. If you want it to always be in English, use EnglishName.

I just found this: http://www.csharp-examples.net/culture-names/

not sure if it helps.

Something like this will work:

var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
var en = allCultures.FirstOrDefault (c => c.Name == "en").DisplayName;
var de = allCultures.FirstOrDefault (c => c.Name == "de").DisplayName;

CultureInfo.DisplayName will contain what you are looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM