Skip to content

Instantly share code, notes, and snippets.

@brettz9
Last active January 3, 2019 17:19
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brettz9/6150009 to your computer and use it in GitHub Desktop.
Save brettz9/6150009 to your computer and use it in GitHub Desktop.
navigator.language
// 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