From 862303722413cca28aacee9af0eeada2ed2047d7 Mon Sep 17 00:00:00 2001 From: Joseph Garrone Date: Sat, 21 Sep 2024 22:35:30 +0200 Subject: [PATCH] Various little adjustments relative to the new i18n API --- src/account/index.ts | 2 +- src/login/i18n/noJsx/index.ts | 1 + src/login/i18n/withJsx/index.ts | 1 + src/login/i18n/withJsx/useI18n.tsx | 2 ++ src/login/index.ts | 2 +- src/login/lib/useUserProfileForm.tsx | 2 +- stories/account/i18n.ts | 8 ++++++-- stories/login/i18n.ts | 6 +++--- test/login/i18n.typelevel-spec.ts | 5 ++++- 9 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/account/index.ts b/src/account/index.ts index cbe11f05..eba44294 100644 --- a/src/account/index.ts +++ b/src/account/index.ts @@ -1,3 +1,3 @@ export type { ExtendKcContext } from "keycloakify/account/KcContext"; export type { ClassKey } from "keycloakify/account/TemplateProps"; -export { createUseI18n } from "keycloakify/account/i18n"; +export { i18nInitializer, type MessageKey_defaultSet } from "keycloakify/account/i18n"; diff --git a/src/login/i18n/noJsx/index.ts b/src/login/i18n/noJsx/index.ts index 61f02521..503af5f5 100644 --- a/src/login/i18n/noJsx/index.ts +++ b/src/login/i18n/noJsx/index.ts @@ -1,2 +1,3 @@ +export type { KcContextLike } from "./getI18n"; export { i18nInitializer } from "./i18nInitializer"; export type { MessageKey as MessageKey_defaultSet } from "../messages_defaultSet/types"; diff --git a/src/login/i18n/withJsx/index.ts b/src/login/i18n/withJsx/index.ts index 61f02521..f8db579b 100644 --- a/src/login/i18n/withJsx/index.ts +++ b/src/login/i18n/withJsx/index.ts @@ -1,2 +1,3 @@ export { i18nInitializer } from "./i18nInitializer"; +export type { KcContextLike } from "./useI18n"; export type { MessageKey as MessageKey_defaultSet } from "../messages_defaultSet/types"; diff --git a/src/login/i18n/withJsx/useI18n.tsx b/src/login/i18n/withJsx/useI18n.tsx index 0abc7bb8..8ddaca9e 100644 --- a/src/login/i18n/withJsx/useI18n.tsx +++ b/src/login/i18n/withJsx/useI18n.tsx @@ -12,6 +12,8 @@ export type ReturnTypeOfCreateUseI18n; }; +export { KcContextLike }; + export function createUseI18n< ThemeName extends string = string, MessageKey_themeDefined extends string = never, diff --git a/src/login/index.ts b/src/login/index.ts index a6718f84..620a7fb0 100644 --- a/src/login/index.ts +++ b/src/login/index.ts @@ -1,3 +1,3 @@ export type { ExtendKcContext, Attribute } from "keycloakify/login/KcContext"; export type { ClassKey } from "keycloakify/login/TemplateProps"; -export { createUseI18n, i18nApi } from "keycloakify/login/i18n"; +export { i18nInitializer, type MessageKey_defaultSet } from "keycloakify/login/i18n"; diff --git a/src/login/lib/useUserProfileForm.tsx b/src/login/lib/useUserProfileForm.tsx index 73859cb8..4e3ff1d2 100644 --- a/src/login/lib/useUserProfileForm.tsx +++ b/src/login/lib/useUserProfileForm.tsx @@ -10,7 +10,7 @@ import { useInsertScriptTags } from "keycloakify/tools/useInsertScriptTags"; import type { PasswordPolicies, Attribute, Validators } from "keycloakify/login/KcContext"; import type { KcContext } from "../KcContext"; import type { MessageKey_defaultSet } from "keycloakify/login/i18n"; -import { KcContextLike as KcContextLike_i18n } from "keycloakify/login/i18n"; +import type { KcContextLike as KcContextLike_i18n } from "keycloakify/login/i18n"; import type { I18n } from "../i18n"; export type FormFieldError = { diff --git a/stories/account/i18n.ts b/stories/account/i18n.ts index 678cbf0b..3a71380f 100644 --- a/stories/account/i18n.ts +++ b/stories/account/i18n.ts @@ -1,5 +1,9 @@ -import { createUseI18n } from "../../dist/account"; +import { i18nInitializer } from "../../dist/account"; +import type { ThemeName } from "../kc.gen"; -export const { useI18n, ofTypeI18n } = createUseI18n({}); +export const { useI18n, ofTypeI18n } = i18nInitializer + .withThemeName() + .withCustomTranslations({}) + .create(); export type I18n = typeof ofTypeI18n; diff --git a/stories/login/i18n.ts b/stories/login/i18n.ts index 39eced84..52e27ffb 100644 --- a/stories/login/i18n.ts +++ b/stories/login/i18n.ts @@ -1,9 +1,9 @@ -import { i18nApi } from "../../dist/login"; +import { i18nInitializer } from "../../dist/login"; import type { ThemeName } from "../kc.gen"; -export const { useI18n, ofTypeI18n } = i18nApi +export const { useI18n, ofTypeI18n } = i18nInitializer .withThemeName() - .withTranslations({}) + .withCustomTranslations({}) .create(); export type I18n = typeof ofTypeI18n; diff --git a/test/login/i18n.typelevel-spec.ts b/test/login/i18n.typelevel-spec.ts index af253ccd..507e6a33 100644 --- a/test/login/i18n.typelevel-spec.ts +++ b/test/login/i18n.typelevel-spec.ts @@ -5,7 +5,10 @@ import { Reflect } from "tsafe/Reflect"; const { useI18n, ofTypeI18n } = i18nInitializer .withThemeName<"my-theme-1" | "my-theme-2">() .withExtraLanguages({ - he: () => import("./he") + he: { + label: "עברית", + getMessages: () => import("./he") + } }) .withCustomTranslations({ en: {