i18n rebuild from the ground up

This commit is contained in:
garronej
2022-04-27 21:02:10 +02:00
parent cc8b2e72c1
commit 7e7071305f
26 changed files with 288 additions and 361 deletions

View File

@ -1,35 +1,30 @@
import "./tools/Array.prototype.every";
import { useMemo, useReducer, Fragment } from "react";
import type { KcContextBase, Validators, Attribute } from "./getKcContext/KcContextBase";
import { useKcMessage } from "./i18n/useKcMessage";
import { getMsg } from "./i18n";
import type { KcLanguageTag } from "./i18n";
import { useConstCallback } from "powerhooks/useConstCallback";
import { id } from "tsafe/id";
import type { MessageKey } from "./i18n/useKcMessage";
import type { MessageKey } from "./i18n";
import { emailRegexp } from "./tools/emailRegExp";
export type KcContextLike = {
messagesPerField: Pick<KcContextBase.Common["messagesPerField"], "existsError" | "get">;
attributes: { name: string; value?: string; validators: Validators }[];
passwordRequired: boolean;
realm: { registrationEmailAsUsername: boolean };
};
export function useGetErrors(params: {
kcContext: {
messagesPerField: Pick<KcContextBase.Common["messagesPerField"], "existsError" | "get">;
profile: {
attributes: { name: string; value?: string; validators: Validators }[];
};
locale?: { currentLanguageTag: KcLanguageTag };
};
}) {
const {
kcContext: {
messagesPerField,
profile: { attributes },
},
} = params;
const { kcContext } = params;
const { msg, msgStr, advancedMsg, advancedMsgStr } = useKcMessage();
const {
messagesPerField,
profile: { attributes },
} = kcContext;
const { msg, msgStr, advancedMsg, advancedMsgStr } = getMsg(kcContext);
const getErrors = useConstCallback((params: { name: string; fieldValueByAttributeName: Record<string, { value: string }> }) => {
const { name, fieldValueByAttributeName } = params;