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