A simple JavaScript library that tells you the accepted languages of the visitor configured in their browser, and the languages relevant given the languages that the current page is alternatively available in.
npm install acceptedlanguages
A simple JavaScript library that exposes the accepted languages of the visitor configured in their browser, and the languages relevant given the languages that the current page is alternatively available in.
``bash`
bower install acceptedlangauges
Download acceptedlanguages.min.js.
Include acceptedlanguages.js into the page and call any of the global properties.
`html`
If the browser is configured with the languages pt, zh-Hans, en-US, the above would output:
`text`
Accepted: pt-BR,pt,zh-Hans,en-US
Alternate: pt-BR,es,en
Relevant: pt-BR,en
Include the library and then use as a dependency:
`javascript`
define(['acceptedlanguages'], function(acceptedLanguages) {
console.log('Accepted: ' + acceptedlanguages.accepted);
console.log('Alternate: ' + acceptedlanguages.alternate);
console.log('Relevant: ' + acceptedlanguages.relevant);
});
All browsers supporting ECMAScript 5: Chrome, Safari, Firefox, IE9, etc. If you need to support older browsers use es5-shims to get the following:
* Array.forEachArray.filter
* Array.map`
*
Expect that Chrome and Firefox may return multiple languages while Safari and IE will return only a single language.