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