A simple function which returns current locale.
Install it with:
$ npm install current_locale
Write in your code:
var currentLocaleFunction = ;var currentLocale =;
currentLocale variable now contains your locale.
console; // 'en-US'
It has two options:
supportedLocalesis an array of supported locales. If it is passed and the browser locale is not one of them, then the function will return false.
fallbackLocaleis a name of a locale which should be returned if browser locale is not one of supportedLocales.
If you do not provide any options, this function will return whatever browser says about current locale, which is usually right.
It supports isomorphic apps. When
navigator is undefined, it returns fallbackLocale you passed.
All modern browsers and even some IEs.
Test it with this command: