detectNearestBrowserLocale(supportedLocales)
Detects the nearest browser locale.
argument | description |
---|---|
supportedLocales |
An array of the supported locales. |
Returns the first matching supported locale.
npm i detect-nearest-browser-locale
import detectNearestBrowserLocale from 'detect-nearest-browser-locale';
<script src="https://unpkg.com/detect-nearest-locale"></script>
<script src="https://unpkg.com/detect-nearest-browser-locale"></script>
// navigator.languages => ['de', 'en-GB']
let locale = detectNearestBrowserLocale(['ru', 'en-US']);
// => 'en-US'