Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to get the name of the current UI language in a javascript file. I know the following trick:

SP.Res.lcid

But that gets the the LCID. What I really need is the two-letter iso name (like 'en', 'fr', etc)

share|improve this question

2 Answers 2

up vote 5 down vote accepted

You can create a JS object and fetch the values using the LCID:

var CultureNames = { 1033:"en", 1036:"fr" };//Store it in a utility file somewhere.

var currentCultureName = CultureNames[SP.Res.lcid]; //will return 'en' if current culture is english.
share|improve this answer
    
To avoid having to keep a utility file around, I eventually used javascript to read the 'lang' attribute of the 'html'-tag. With a substring I can get 'en' out of 'en-us'. The reason I did this is that I have another library which keeps languages but in the two-letter format. It's a bit silly to keep two such repositories. Now I just hope that SharePoint will continue to mention that attribute. –  Spongeroberto Squarepantalones Nov 2 '12 at 13:42

I created a JavaScript library to handle your requirement (returns the culture name from a decimal lcid value)

The mapping comes from this page: National Language Support (NLS) API Reference (Windows 7)

Practically inside the library there is JSON object with the values and two methods to get them.

The Culture name is the full one (for example en-US for 1033) you can slice the string if you need only the first two letters.

You can find more information on my blog:

LCID JavaScript Helper Library

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.