diff options
author | Sebastian <sebasjm@gmail.com> | 2022-03-14 12:15:41 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-03-14 15:21:24 -0300 |
commit | 1d7c8f7083f2aa98295f1ad28399c8e19a9e7754 (patch) | |
tree | 9b4caab47b95a27f63f79285732616cb5f7275fe /packages/taler-wallet-webextension/src/hooks | |
parent | 85e5a24e5fa4d40e6d597eab21ea3724a603d64e (diff) | |
download | wallet-core-1d7c8f7083f2aa98295f1ad28399c8e19a9e7754.tar.xz |
WIP fixing translation context
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks')
-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); } |