-1

I'm trying to set the CultureInfo of my application depending on a settingFile that's being given to me (I can't change it's content).

In my settingFile I have only access to the language name that I should display (no information about the country) for example German, French, English.

I managed to get my CultureInfo using

CultureInfo cultureInfo = CultureInfo.GetCultures(CultureTypes.AllCultures)
                              .Where(c => c.EnglishName == languageName).FirstOrDefault();

My problem is that I'm now supposed to do :

Thread.CurrentThread.CurrentCulture = new CultureInfo({LANG-COUNTRY});

But I only have the language (via cultureInfo.Name), so I can't create my culture info.

Trying to do

Thread.CurrentThread.CurrentCulture = cultureInfo;

did not work either.

I thought about doing

new CulltureInfo({cultureInfo.Name+"-"+cultureInfo.Name.ToUpper()});

but it doesn't work for example with English ...

Is there a way to set my CultureInfo to the most common country related to my language ?
I know it will not be a perfect solution (for example what would be the most common between en-UK and en-US ...) but I don't think I can do better, not knowing the country of my user.

Belterius
  • 738
  • 1
  • 10
  • 20

1 Answers1

1

This var en = CultureInfo.GetCultures (CultureTypes.AllCultures).First(x=>x.Name=="en"); will give you a base CultureInfo for your language (en in the example). If you'll examine "en-GB", "en-US" than you can see both have Parent equal to "en".

Leonid Malyshev
  • 475
  • 1
  • 6
  • 14
  • Maybe I misunderstood your explaination, but `var en = CultureInfo.GetCultures (CultureTypes.AllCultures).First(x=>x.Name=="en");` is doing exactly the same as `CultureInfo cultureInfo = CultureInfo.GetCultures(CultureTypes.AllCultures) .Where(c => c.EnglishName == "English").FirstOrDefault();` and I still have the same problem, no way to know the possible countries (or most popular) for this language, and so no way to create my `new CultureInfo({LANG-COUNTRY})` – Belterius Jul 28 '16 at 13:45
  • Possible countries (cultures) you can get using filter First(x=>x.Parent.Name=="en") instead of Name. And to get most popular is not about programming but about demography and statistics. And my example gives you cultore without region set. – Leonid Malyshev Jul 28 '16 at 13:51
  • Just first variant gives you CultureType neutral, and second - country specific. – Leonid Malyshev Jul 28 '16 at 14:09
  • Oh right I didn't think I could use the parent in my query, I can indeed retrieve a lang+country now, thank you. – Belterius Jul 28 '16 at 14:15