https://github.com/wix-incubator/locale-helpers
Infers the best valid locale for a given language/country combination
https://github.com/wix-incubator/locale-helpers
Last synced: 8 months ago
JSON representation
Infers the best valid locale for a given language/country combination
- Host: GitHub
- URL: https://github.com/wix-incubator/locale-helpers
- Owner: wix-incubator
- License: apache-2.0
- Created: 2016-12-21T13:51:46.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-02-22T08:52:17.000Z (over 3 years ago)
- Last Synced: 2025-04-05T15:01:52.717Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 6
- Watchers: 276
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - locale-helpers
README
# locale-helpers
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url]
Infers the best valid locale for a given language/country combination.
Sometimes the locale is simply the language/country combination, e.g. ```en``` + ```US``` = ```en_US```.
However, ```it``` + ```FR``` ≠ ```it_FR``` (as it is not a valid locale). A better option is the valid ```it_IT```.
### Usage
Install the library with `npm install locale-helpers`
```javascript
var LocaleHelpers = require('locale-helpers').LocaleHelpers;
LocaleHelpers.bestLocaleFor({language: 'en', country: 'US'}); //-> 'en_US'
LocaleHelpers.bestLocaleFor({language: 'fr', country: 'FR'}); //-> 'fr_FR'
LocaleHelpers.bestLocaleFor({language: 'en', country: 'GB'}); //-> 'en_GB'
LocaleHelpers.bestLocaleFor({language: 'it', country: 'FR'}); //-> 'it_IT'
```
[downloads-image]: https://img.shields.io/npm/dm/locale-helpers.svg
[npm-url]: https://npmjs.org/package/locale-helpers
[npm-image]: https://img.shields.io/npm/v/locale-helpers.svg