Skip to content

Instantly share code, notes, and snippets.

@PatrickJS
Forked from brettz9/navigator.language.js
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save PatrickJS/a75f2922ed57352a1b2a to your computer and use it in GitHub Desktop.

Select an option

Save PatrickJS/a75f2922ed57352a1b2a to your computer and use it in GitHub Desktop.
// Defined: http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#navigatorlanguage
// with allowable values at http://www.ietf.org/rfc/bcp/bcp47.txt
// Note that the HTML spec suggests that anonymizing services return "en-US" by default for
// user privacy (so your app may wish to provide a means of changing the locale)
navigator.language = navigator.language ||
// IE 10 in IE8 mode on Windows 7 uses upper-case in
// navigator.userLanguage country codes but per
// http://msdn.microsoft.com/en-us/library/ie/ms533052.aspx (via
// http://msdn.microsoft.com/en-us/library/ie/ms534713.aspx), they
// appear to be in lower case, so we bring them into harmony with navigator.language.
(navigator.userLanguage && navigator.userLanguage.replace(/-[a-z]{2}$/, String.prototype.toUpperCase)) ||
'en-US'; // Default for anonymizing services: http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#navigatorlanguage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment