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.
npm i detect-nearest-locale
import detectNearestLocale from 'detect-nearest-locale';
<script src="https://unpkg.com/detect-nearest-locale"></script>
let locale = detectNearestLocale(['ru', 'en-US'], ['de', 'en-GB']);
// => 'en-US'