1

I want to get the current site language as I am implementing a custom module that will depend on web language. I am new to SharePoint and the company is using multi language site or site collection.

0

There are many ways to retrieve site's language. Using javascript:

//Current Language
console.log(_spPageContextInfo.currentCultureName);
console.log(_spPageContextInfo.currentLanguage);
console.log(_spPageContextInfo.webLanguage);
console.log(SP.Res.lcid);

var currentLocale = "<%= SPContext.Current.Web.Language %>";
var globalLocale = "<%= SPContext.Current.Web.Language %>";
document.getElementsByTagName('html')[0].getAttribute('lang');
  • Can you explain to me what is the SP.Res – Marc May 13 '16 at 15:47
  • It's equivalent to .resx file but in client side. Open you fav console editor (Firebug, IE tools, chrome ) and type SP.Res. you'll see all the available properties and values – Aveenav May 13 '16 at 15:53
0

You can try below code:

SPContext.Current.RegionalSettings.LocaleId - Gets the regional settings object of the current HTTP context in Microsoft SharePoint Foundation.

Also you could load language from current web

SPContext.Current.Web.Language - Gets the locale identifier (LCID) for the default language of the website.

Reference: https://social.technet.microsoft.com/Forums/en-US/e12a6797-e6b2-44c8-840c-1c09623b7a84/how-to-get-the-language-of-current-sharepoint-portal?forum=sharepointgeneralprevious

SPWeb.Language property

To Use Java Script:

You have two easy ways to get the LCID in SP JavaScript

  1. var lcid =_spPageContextInfo.currentLanguage;
  2. var lcid = SP.Res.lcid;

Get the current UI language with ECMAScript

0

You can use JavaScript, there's an object available for you called: _spPageContextInfo, and then you can access currentLanguage, like:

_spPageContextInfo.currentLanguage

It will give you the language ID, in English it's 1033. You have to know ID for each language you want and that's it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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