https://github.com/seregpie/detectnearestbrowserlocale
Detects the nearest browser locale.
https://github.com/seregpie/detectnearestbrowserlocale
browser detect language locale navigator
Last synced: 5 months ago
JSON representation
Detects the nearest browser locale.
- Host: GitHub
- URL: https://github.com/seregpie/detectnearestbrowserlocale
- Owner: SeregPie
- License: mit
- Created: 2018-05-24T17:34:03.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-05T11:31:30.000Z (about 6 years ago)
- Last Synced: 2024-04-24T23:40:35.625Z (about 1 year ago)
- Topics: browser, detect, language, locale, navigator
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# detectNearestBrowserLocale
`detectNearestBrowserLocale(supportedLocales)`
Detects the nearest browser locale.
| argument | description |
| ---: | :--- |
| `supportedLocales` | An array of the supported locales. |Returns the first matching supported locale.
## dependencies
- [detectNearestLocale](https://github.com/SeregPie/detectNearestLocale)
## setup
### npm
```shell
npm i detect-nearest-browser-locale
```### ES module
```javascript
import detectNearestBrowserLocale from 'detect-nearest-browser-locale';
```### browser
```html
```
## usage
```javascript
// navigator.languages => ['de', 'en-GB']
let locale = detectNearestBrowserLocale(['ru', 'en-US']);
// => 'en-US'
```