Skip to content

normalizes weird cross browser issues and tries to return the users selected language in 100% client side JS by looking at various properties on the `window.navigator` object

Notifications You must be signed in to change notification settings

moimikey/browser-locale

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

browser-locale

NPM

normalizes weird cross browser issues and tries to return the users selected language in 100% client side JS by looking at various properties on the window.navigator object

note that another technique used to detect the browsers user-set language preference is to look at the accept-language header set on outgoing http requests, but this requires making a round trip XHR to a server, which is what jquery-browser-language does.

however, it seems that as of 2014 you can get the user specified language without making a HTTP request (see index.js for details)

installation

npm install browser-locale

use browserify or browserify-cdn to package it for browser use

usage

var locale = require('browser-locale')()
// locale will be e.g. en-US or undefined if it could not be detected (e.g. you are in a super weird browser)

tips

Not all browsers are consistent in their capitalization of language tags, e.g. en-US vs en-us. Keep this in mind when looking for matches in locale strings.

See also locale2, an alternative module for detecting a user's locale.

About

normalizes weird cross browser issues and tries to return the users selected language in 100% client side JS by looking at various properties on the `window.navigator` object

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%