https://github.com/seregpie/detectnearestlocale
Detects the nearest preferred locale.
https://github.com/seregpie/detectnearestlocale
Last synced: 5 months ago
JSON representation
Detects the nearest preferred locale.
- Host: GitHub
- URL: https://github.com/seregpie/detectnearestlocale
- Owner: SeregPie
- License: mit
- Created: 2019-02-27T20:59:07.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-03-05T11:33:24.000Z (about 6 years ago)
- Last Synced: 2024-12-09T04:39:51.405Z (5 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# detectNearestLocale
`detectNearestLocale(supportedLocales, preferredLocales)`
Detects the nearest preferred locale.
| argument | description |
| ---: | :--- |
| `supportedLocales` | An array of the supported locales. |
| `preferredLocales` | An array of the preferred locales. |Returns the first matching supported locale.
## setup
### npm
```shell
npm i detect-nearest-locale
```### ES module
```javascript
import detectNearestLocale from 'detect-nearest-locale';
```### browser
```html
```
## usage
```javascript
let locale = detectNearestLocale(['ru', 'en-US'], ['de', 'en-GB']);
// => 'en-US'
```## see also
- [detectNearestBrowserLocale](https://github.com/SeregPie/detectNearestBrowserLocale)