An open API service indexing awesome lists of open source software.

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.

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)