536 B
536 B
title, tags
| title | tags |
|---|---|
| detectLanguage | browser,intermediate |
Detects the preferred language of the current user.
- Use
NavigationLanguage.languageor the firstNavigationLanguage.languagesif available, otherwise returndefaultLang. - Omit the second argument,
defaultLang, to use'en-US'as the default language code.
const detectLanguage = (defaultLang = 'en-US') =>
navigator.language ||
(Array.isArray(navigator.languages) && navigator.languages[0]) ||
defaultLang;
detectLanguage(); // 'nl-NL'