Better i18n API
This commit is contained in:
@ -69,11 +69,11 @@ export type GenericI18n<MessageKey extends string> = {
|
|||||||
|
|
||||||
export type I18n = GenericI18n<MessageKeyBase>;
|
export type I18n = GenericI18n<MessageKeyBase>;
|
||||||
|
|
||||||
export function useGenericI18n<ExtraMessageKey extends string = never>(params: {
|
export function createUseI18n<ExtraMessageKey extends string = never>(extraMessages: {
|
||||||
kcContext: KcContextLike;
|
[languageTag: string]: { [key in ExtraMessageKey]: string };
|
||||||
extraMessages: { [languageTag: string]: { [key in ExtraMessageKey]: string } };
|
}) {
|
||||||
}): GenericI18n<MessageKeyBase | ExtraMessageKey> | null {
|
function useI18n(params: { kcContext: KcContextLike }): GenericI18n<MessageKeyBase | ExtraMessageKey> | null {
|
||||||
const { kcContext, extraMessages } = params;
|
const { kcContext } = params;
|
||||||
|
|
||||||
const [i18n, setI18n] = useState<GenericI18n<ExtraMessageKey | MessageKeyBase> | undefined>(undefined);
|
const [i18n, setI18n] = useState<GenericI18n<ExtraMessageKey | MessageKeyBase> | undefined>(undefined);
|
||||||
|
|
||||||
@ -178,6 +178,9 @@ export function useGenericI18n<ExtraMessageKey extends string = never>(params: {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return i18n ?? null;
|
return i18n ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return { useI18n };
|
||||||
}
|
}
|
||||||
|
|
||||||
function createI18nTranslationFunctions<MessageKey extends string>(params: {
|
function createI18nTranslationFunctions<MessageKey extends string>(params: {
|
||||||
|
@ -5,6 +5,6 @@ export default Fallback;
|
|||||||
export { createKeycloakAdapter } from "keycloakify/lib/keycloakJsAdapter";
|
export { createKeycloakAdapter } from "keycloakify/lib/keycloakJsAdapter";
|
||||||
export { useDownloadTerms } from "keycloakify/lib/useDownloadTerms";
|
export { useDownloadTerms } from "keycloakify/lib/useDownloadTerms";
|
||||||
export { getKcContext } from "keycloakify/kcContext/getKcContext";
|
export { getKcContext } from "keycloakify/kcContext/getKcContext";
|
||||||
export { useGenericI18n } from "keycloakify/i18n";
|
export { createUseI18n } from "keycloakify/i18n";
|
||||||
|
|
||||||
export type { PageProps } from "keycloakify/pages/PageProps";
|
export type { PageProps } from "keycloakify/pages/PageProps";
|
||||||
|
Reference in New Issue
Block a user