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.
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".