0

Given a list of cultures, I want to retrieve their display names based on a culture other than my own. Using "en", "de" and "fr" querying CultureInfo for them on my machine (US version of Windows 10 set to culture "en-ZA") gives the following result.

de => { EnglishName="German",  NativeName="Deutsch",  DisplayName="German" }
en => { EnglishName="English", NativeName="English",  DisplayName="English" }  
fr => { EnglishName="French",  NativeName="français", DisplayName="French" }  

I would like to retrieve names matching the arguments and lists below

de => { Deutsch, Englisch, Französisch }
en => { German, English, French }
fr => { allemand, Anglais, français }

Note that these may be slightly incorrect as I had assistance from Google Translate, but I think you'll get the idea.

I had hoped I might simply be able to set the culture for the thread before retrieving the DisplayName as follows.

CultureInfo myCulture = Thread.CurrentThread.CurrentCulture;
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de");
string english = CultureInfo.GetCultureInfo("en").DisplayName; // hoped for "Englisch"
string french = CultureInfo.GetCultureInfo("fr").DisplayName; // hoped for "Französisch"
string german = CultureInfo.GetCultureInfo("de").DisplayName; // hoped for "Deutsch"
Thread.CurrentThread.CurrentCulture = myCulture;

But this does not work and in each case DisplayName for any culture is always the same as EnglishName.

Is there something I'm missing in .NET (or even a third-party library) that can help me get what I need or am I going to have to build hard-coded lists? I would like to avoid that as I currently need this for around 30 languages and more could be added at any time.

Steve Crane
  • 4,340
  • 5
  • 40
  • 63
  • Depending on what this is for consider that if I speak a language then I don't need the language name translated. ie if I speak German I will know that "Deutsch" means German without it needing to be translated into English. If I don't know that it means German then I probably don't want to be selecting it anyway... It will depend on exactly what you are doing with localisation though. – Chris Jul 10 '17 at 15:12
  • 1
    Chris, you're right about it depending on the use. Building a list of native language names for a user to select their own from is easy and already catered for by CultureInfo.NativeName. In this case I want to build a list of language names for an administrator to select from, in his or her own language. For example the NativeName for zh-TW is 中文(台灣) and the EnglishName is Chinese (Traditional, Taiwan), but what should it be for a German, Spanish, Swahili or other language speaker? They may not recognise either the NativeName or EnglishName. – Steve Crane Jul 10 '17 at 19:54
  • Cool. I figured there was a reasonable chance that it would be something like that but thought I'd comment just in case it was something else! :) – Chris Jul 11 '17 at 08:11

0 Answers0