current-locale

1.0.7 • Public • Published

current-locale

npm version

What

A simple function which returns current locale.

Example usage

  1. Install it with: $ npm install current_locale

  2. Write in your code:

var currentLocaleFunction = require('current-locale');
 
var currentLocale = currentLocaleFunction({
  supportedLocales: ['ru', 'en-US'],
  fallbackLocale: 'en-US'
});

currentLocale variable now contains your locale.

console.log(currentLocale); // 'en-US'

Options?

It has two options:

  • supportedLocales is an array of supported locales. If it is passed and the browser locale is not one of them, then the function will return false.
  • fallbackLocale is 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.

Isomorphic

It supports isomorphic apps. When navigator is undefined, it returns fallbackLocale you passed.

Browser support

All modern browsers and even some IEs.

Testing

Test it with this command: $ mocha

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.7
    0
    • latest

Version History

Package Sidebar

Install

npm i current-locale

Weekly Downloads

1

Version

1.0.7

License

MIT

Last publish

Collaborators

  • cbrwizard