How to Set the Language of an HTML Doc in JavaScript

Cloudmersive
1 min readJul 9, 2021

--

There are certain components that are essential to every HTML document, regardless of its content; one such component is the language code. This two-letter combination denotes the language of the document such as ‘en’ for English, or ‘es’ for Spanish. If you regularly need to set the language of HTML documents, we have a solution you can use in JavaScript that will automate and simplify the process.

To begin, we will need to run this command to install jQuery:

bower install jquery

Now, we are ready to call our API function by inputting the file or file URL along with the preferred language code into the below:

var settings = {
"url": "https://api.cloudmersive.com/convert/edit/html/head/set/language",
"method": "POST",
"timeout": 0,
"headers": {
"inputFileUrl": "<string>",
"languageCode": "<string>",
"Content-Type": "application/x-www-form-urlencoded",
"Apikey": "YOUR-API-KEY-HERE"
},
"data": {
"inputFile": "<binary>"
}
};
$.ajax(settings).done(function (response) {
console.log(response);
});

To retrieve your API key, visit the Cloudmersive website to register for a free account; this will provide 800 monthly calls across our library of APIs.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet