Reputation: 3502
I want to get the current language. I have try like this.
Console.WriteLine("Tese 1==> " + CultureInfo.CurrentCulture.EnglishName);
Console.WriteLine("Test 2==> " + CultureInfo.CurrentUICulture.EnglishName);
Here i getting output like English(United States)
.
But i want only 'English'. How to get the language alone.
Now i use other method to get the Output.
currentCulture = CultureInfo.CurrentUICulture.EnglishName;
string[] values = currentCulture.Split('(').Select(sValue => sValue.Trim()).ToArray();
Console.WriteLine("Language ==> " + values.ElementAt(0));
Is there any default method to get the current language alone.
Upvotes: 1
Views: 116
Reputation: 4198
Get the neutral culture from your CurrentCulture
and use it's name:
var culture = CultureInfo.CurrentCulture;
if (!culture.IsNeutralCulture)
culture = culture.Parent;
Console.WriteLine(culture.EnglishName);
For example for "en-us" or "en-gb" the parent culture is "en" with the name "English".
Upvotes: 2
Reputation: 2621
Unfortunately You can not have it directly. you would get the culture name in the format language (country/region)
by using DisplayName
Property or
the culture name in the format languagecode-country/regioncode
by using Name
Property. for Getting Your Desired Output you are needed to manipulate
the String what you are Getting from Properties.
Upvotes: 0
Reputation: 683
Look here : How to get the Windows Phone system language from code?
Original Answer:
System.Threading.Thread.CurrentThread.CurrentCulture
Upvotes: 0