diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks/useLang.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/hooks/useLang.ts | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useLang.ts b/packages/taler-wallet-webextension/src/hooks/useLang.ts index cc4ff3fc8..7215f2256 100644 --- a/packages/taler-wallet-webextension/src/hooks/useLang.ts +++ b/packages/taler-wallet-webextension/src/hooks/useLang.ts @@ -16,11 +16,13 @@ import { useNotNullLocalStorage } from "./useLocalStorage"; +function getBrowserLang(): string | undefined { + if (window.navigator.languages) return window.navigator.languages[0] + if (window.navigator.language) return window.navigator.language + return undefined; +} + export function useLang(initial?: string): [string, (s: string) => void] { - const browserLang: string | undefined = - typeof window !== "undefined" - ? navigator.language || (navigator as any).userLanguage - : undefined; - const defaultLang = (browserLang || initial || "en").substring(0, 2); + const defaultLang = (getBrowserLang() || initial || "en").substring(0, 2); return useNotNullLocalStorage("lang-preference", defaultLang); } |