diff options
author | Sebastian <sebasjm@gmail.com> | 2022-12-06 11:21:12 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-12-06 11:21:12 -0300 |
commit | d3a6544bc5fd7b3d2d65494ba1c3155b024a436e (patch) | |
tree | 8e66fcbd9f1ae79fa5d9288af70a827caedb2c91 /packages/anastasis-webui/src/context/translation.ts | |
parent | e382b022030db96b8282337b304ec5e599a5f405 (diff) | |
download | wallet-core-d3a6544bc5fd7b3d2d65494ba1c3155b024a436e.tar.xz |
using web-utils in anastasis-webui
Diffstat (limited to 'packages/anastasis-webui/src/context/translation.ts')
-rw-r--r-- | packages/anastasis-webui/src/context/translation.ts | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/packages/anastasis-webui/src/context/translation.ts b/packages/anastasis-webui/src/context/translation.ts index 87704a13f..44faaa456 100644 --- a/packages/anastasis-webui/src/context/translation.ts +++ b/packages/anastasis-webui/src/context/translation.ts @@ -19,23 +19,42 @@ * @author Sebastian Javier Marchano (sebasjm) */ +import { i18n, setupI18n } from "@gnu-taler/taler-util"; import { createContext, h, VNode } from "preact"; import { useContext, useEffect } from "preact/hooks"; -import { useLang } from "../hooks/index.js"; -import * as jedLib from "jed"; +import { useLang } from "../hooks/useLang.js"; import { strings } from "../i18n/strings.js"; interface Type { lang: string; - handler: any; + supportedLang: { [id in keyof typeof supportedLang]: string }; changeLanguage: (l: string) => void; + i18n: typeof i18n; + isSaved: boolean; } + +const supportedLang = { + es: "Español [es]", + ja: "日本語 [ja]", + en: "English [en]", + fr: "Français [fr]", + de: "Deutsch [de]", + sv: "Svenska [sv]", + it: "Italiano [it]", + // ko: "한국어 [ko]", + // ru: "Ру́сский язы́к [ru]", + tr: "Türk [tr]", + navigator: "Defined by navigator", +}; + const initial = { lang: "en", - handler: null, + supportedLang, changeLanguage: () => { // do not change anything }, + i18n, + isSaved: false, }; const Context = createContext<Type>(initial); @@ -50,15 +69,23 @@ export const TranslationProvider = ({ children, forceLang, }: Props): VNode => { - const [lang, changeLanguage] = useLang(initial); + const [lang, changeLanguage, isSaved] = useLang(initial); useEffect(() => { if (forceLang) { changeLanguage(forceLang); } }); - const handler = new jedLib.Jed(strings[lang] || strings["en"]); + useEffect(() => { + setupI18n(lang, strings); + }, [lang]); + if (forceLang) { + setupI18n(forceLang, strings); + } else { + setupI18n(lang, strings); + } + return h(Context.Provider, { - value: { lang, handler, changeLanguage }, + value: { lang, changeLanguage, supportedLang, i18n, isSaved }, children, }); }; |