Refactor: Use hook instead of Context for i18n

This commit is contained in:
garronej
2022-07-31 22:30:32 +02:00
parent 0641151ca1
commit 7a0a046596
22 changed files with 238 additions and 222 deletions

View File

@ -8,7 +8,7 @@ import { pathJoin } from "../../bin/tools/pathJoin";
import { useConstCallback } from "powerhooks/useConstCallback";
import type { KcTemplateProps } from "./KcProps";
import { useCssAndCx } from "tss-react";
import { useI18n } from "../i18n";
import type { I18n } from "../i18n";
export type TemplateProps = {
displayInfo?: boolean;
@ -24,7 +24,7 @@ export type TemplateProps = {
* to avoid pulling the default theme assets.
*/
doFetchDefaultThemeResources: boolean;
} & { kcContext: KcContextBase } & KcTemplateProps;
} & { kcContext: KcContextBase; i18n: I18n } & KcTemplateProps;
const Template = memo((props: TemplateProps) => {
const {
@ -38,6 +38,7 @@ const Template = memo((props: TemplateProps) => {
formNode,
infoNode = null,
kcContext,
i18n,
doFetchDefaultThemeResources,
} = props;
@ -47,7 +48,7 @@ const Template = memo((props: TemplateProps) => {
console.log("Rendering this page with react using keycloakify");
}, []);
const { msg, changeLocale, labelBySupportedLanguageTag, currentLanguageTag } = useI18n();
const { msg, changeLocale, labelBySupportedLanguageTag, currentLanguageTag } = i18n;
const onChangeLanguageClickFactory = useCallbackFactory(([kcLanguageTag]: [string]) => changeLocale(kcLanguageTag));