Vijay
Vijay

Reputation: 3502

How to get the current language from windows Phone 7?

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

Answers (3)

lisp
lisp

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

Amit Bhatiya
Amit Bhatiya

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

Bjego
Bjego

Reputation: 683

Look here : How to get the Windows Phone system language from code?

Original Answer:

System.Threading.Thread.CurrentThread.CurrentCulture

Upvotes: 0

Related Questions