diff options
| author | Sebastian <sebasjm@gmail.com> | 2022-12-19 12:23:39 -0300 |
|---|---|---|
| committer | Sebastian <sebasjm@gmail.com> | 2022-12-19 12:23:39 -0300 |
| commit | 72b429321553841ac1ff48cf974bfc65da01bb06 (patch) | |
| tree | 7db9a4462f02de6cb86de695a1e64772b00ead5f /packages/merchant-backoffice-ui/src/context/translation.ts | |
| parent | 770ab6f01dc81a16f384f314982bd761540f8e65 (diff) | |
pretty
Diffstat (limited to 'packages/merchant-backoffice-ui/src/context/translation.ts')
| -rw-r--r-- | packages/merchant-backoffice-ui/src/context/translation.ts | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/packages/merchant-backoffice-ui/src/context/translation.ts b/packages/merchant-backoffice-ui/src/context/translation.ts index 88359a149..027eac14c 100644 --- a/packages/merchant-backoffice-ui/src/context/translation.ts +++ b/packages/merchant-backoffice-ui/src/context/translation.ts @@ -15,13 +15,13 @@ */ /** -* -* @author Sebastian Javier Marchano (sebasjm) -*/ + * + * @author Sebastian Javier Marchano (sebasjm) + */ -import { createContext, h, VNode } from 'preact' -import { useContext, useEffect } from 'preact/hooks' -import { useLang } from '../hooks' +import { createContext, h, VNode } from "preact"; +import { useContext, useEffect } from "preact/hooks"; +import { useLang } from "../hooks"; import * as jedLib from "jed"; import { strings } from "../i18n/strings"; @@ -31,29 +31,36 @@ interface Type { changeLanguage: (l: string) => void; } const initial = { - lang: 'en', + lang: "en", handler: null, changeLanguage: () => { // do not change anything - } -} -const Context = createContext<Type>(initial) + }, +}; +const Context = createContext<Type>(initial); interface Props { - initial?: string, - children: any, - forceLang?: string + initial?: string; + children: any; + forceLang?: string; } -export const TranslationProvider = ({ initial, children, forceLang }: Props): VNode => { - const [lang, changeLanguage] = useLang(initial) +export const TranslationProvider = ({ + initial, + children, + forceLang, +}: Props): VNode => { + const [lang, changeLanguage] = useLang(initial); useEffect(() => { if (forceLang) { - changeLanguage(forceLang) + changeLanguage(forceLang); } - }) + }); const handler = new jedLib.Jed(strings[lang]); - return h(Context.Provider, { value: { lang, handler, changeLanguage }, children }); -} + return h(Context.Provider, { + value: { lang, handler, changeLanguage }, + children, + }); +}; -export const useTranslationContext = (): Type => useContext(Context);
\ No newline at end of file +export const useTranslationContext = (): Type => useContext(Context); |
