SharePoint online: How to retrieve alternative languages from language settings using JSOM
In this post, we will discuss how we can retrieve alternative languages from language settings in SharePoint online using JavaScript object model. You can see the alternative languages from Site settings -> language settings which is under Site Administration. If you want to check how we can do using Rest API, then you can check this article.
It shows like below:
For this particular post, I have added the below code inside a script editor web part.
Remember it will display like for English language it will return 1033.
<input type="button" id="btnGetLanguages" value="Click Here"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btnGetLanguages").click(function(){
GetLanguages();
});
});
var web;
function GetLanguages(){
alert('Hello world');
var clientContext = new SP.ClientContext();
web=clientContext.get_web();
clientContext.load(web,"SupportedUILanguageIds");
clientContext.executeQueryAsync(Function.createDelegate(this, this.onSuccess),
Function.createDelegate(this, this.onFailure));
}
function onSuccess() {
var supportedlanguage = web.get_supportedUILanguageIds();
for (var i = 0; i < supportedlanguage.length; i++) {
var languageName = supportedlanguage[i].toString();
alert(languageName);
}
}
function onFailure(sender, args) {
alert('Error Occurred. ' + args.get_message());
}
</script>