use-browser-language
Reads and subscribes to the browser language preferences
Source
Docs
Package
Usage
use-browser-language returns the browser language from
navigator.language.
The value is updated when the user changes the preferred language in the browser
or operating system settings:
Your browser language: unknown
usePreferredLanguages
usePreferredLanguages returns the list of the user's preferred languages from
navigator.languages,
the most preferred language is first. Use it to find the best match with the locales
that your application supports:
Your preferred languages, most preferred first:
Definition
Reacting to changes
Both hooks subscribe to the window languagechange event and update the value when it fires.
Server-side rendering
During server-side rendering and the first client render, useBrowserLanguage
returns undefined and usePreferredLanguages returns an empty array. The values are set
after the component is mounted.