Instantly share code, notes, and snippets.

@ksol /chrome_39.js
Last active Nov 16, 2018

Embed
What would you like to do?
Language detection in javascript
window.navigator.language // -> "fr"
window.navigator.languages // -> ["fr-FR", "fr", "en-US", "en", "es", "de"]
window.navigator.userLanguage // -> undefined
window.navigator.browserLanguage // -> undefined
window.navigator.systemLanguage // -> undefined
window.navigator.language // -> "fr"
window.navigator.languages // -> [ "fr", "fr-FR", "en-US", "en" ]
window.navigator.userLanguage // -> undefined
window.navigator.browserLanguage // -> undefined
window.navigator.systemLanguage // -> undefined
window.navigator.language // -> undefined
window.navigator.languages // -> undefined
window.navigator.userLanguage // -> 'en-us'
window.navigator.browserLanguage // -> 'en-us'
window.navigator.systemLanguage // -> 'en-us'
window.navigator.language // -> undefined
window.navigator.languages // -> undefined
window.navigator.userLanguage // -> 'en-US'
window.navigator.browserLanguage // -> 'en-US'
window.navigator.systemLanguage // -> 'en-US'
window.navigator.language // -> 'en-US'
window.navigator.languages // -> undefined
window.navigator.userLanguage // -> 'en-US'
window.navigator.browserLanguage // -> 'en-US'
window.navigator.systemLanguage // -> 'en-US'
window.navigator.language // -> "fr-fr"
window.navigator.languages // -> undefined
window.navigator.userLanguage // -> undefined
window.navigator.browserLanguage // -> undefined
window.navigator.systemLanguage // -> undefined
@Slumber86

This comment has been minimized.

Slumber86 commented Apr 27, 2017

Safari 10:

window.navigator.language        // -> "fr-FR"
window.navigator.languages       // -> ["fr-FR", "fr", "en-US", "en", "es", "de"]
window.navigator.userLanguage    // -> undefined
window.navigator.browserLanguage // -> undefined
window.navigator.systemLanguage  // -> undefined 
@DarkMatterMatt

This comment has been minimized.

DarkMatterMatt commented Mar 18, 2018

chrome_65 is still

window.navigator.language        // -> "fr"
window.navigator.languages       // -> ["fr-FR", "fr", "en-US", "en", "es", "de"]
window.navigator.userLanguage    // -> undefined
window.navigator.browserLanguage // -> undefined
window.navigator.systemLanguage  // -> undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment