Compare commits
6 Commits
v10.0.0-rc
...
v10.0.0-rc
Author | SHA1 | Date | |
---|---|---|---|
f37a342a63 | |||
09a039894d | |||
3efbb1a9fd | |||
920ee62ee3 | |||
1ace44fe31 | |||
a60f05415b |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "keycloakify",
|
||||
"version": "10.0.0-rc.83",
|
||||
"version": "10.0.0-rc.85",
|
||||
"description": "Create Keycloak themes using React",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@ -62,9 +62,6 @@
|
||||
"bluehats"
|
||||
],
|
||||
"homepage": "https://www.keycloakify.dev",
|
||||
"peerDependencies": {
|
||||
"react": "*"
|
||||
},
|
||||
"dependencies": {
|
||||
"tsafe": "^1.6.6"
|
||||
},
|
||||
|
@ -3,8 +3,7 @@ import { assert } from "tsafe/assert";
|
||||
import messages_fallbackLanguage from "./baseMessages/en";
|
||||
import { getMessages } from "./baseMessages";
|
||||
import type { KcContext } from "../KcContext";
|
||||
|
||||
export const fallbackLanguageTag = "en";
|
||||
import { fallbackLanguageTag } from "keycloakify/bin/shared/constants";
|
||||
|
||||
export type KcContextLike = {
|
||||
locale?: {
|
||||
|
@ -2,4 +2,3 @@ import type { GenericI18n, MessageKey, KcContextLike } from "./i18n";
|
||||
export type { MessageKey, KcContextLike };
|
||||
export type I18n = GenericI18n<MessageKey>;
|
||||
export { createUseI18n } from "./useI18n";
|
||||
export { fallbackLanguageTag } from "./i18n";
|
||||
|
@ -7,12 +7,12 @@ import {
|
||||
} from "./i18n";
|
||||
import { Reflect } from "tsafe/Reflect";
|
||||
|
||||
export function createUseI18n<ExtraMessageKey extends string = never>(extraMessages: {
|
||||
export function createUseI18n<ExtraMessageKey extends string = never>(messageBundle: {
|
||||
[languageTag: string]: { [key in ExtraMessageKey]: string };
|
||||
}) {
|
||||
type I18n = GenericI18n<MessageKey | ExtraMessageKey>;
|
||||
|
||||
const { getI18n } = createGetI18n(extraMessages);
|
||||
const { getI18n } = createGetI18n(messageBundle);
|
||||
|
||||
function useI18n(params: { kcContext: KcContextLike }): { i18n: I18n } {
|
||||
const { kcContext } = params;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import type { ThemeType } from "../../shared/constants";
|
||||
import { type ThemeType, fallbackLanguageTag } from "../../shared/constants";
|
||||
import { crawl } from "../../tools/crawl";
|
||||
import { join as pathJoin } from "path";
|
||||
import { readFileSync } from "fs";
|
||||
@ -41,7 +41,7 @@ export function generateMessageProperties(params: {
|
||||
readFileSync(file).toString("utf8").includes("createUseI18n")
|
||||
);
|
||||
|
||||
const extraMessages = files
|
||||
const messageBundles = files
|
||||
.map(file => {
|
||||
const root = recast.parse(readFileSync(file).toString("utf8"), {
|
||||
parser: {
|
||||
@ -73,12 +73,12 @@ export function generateMessageProperties(params: {
|
||||
})
|
||||
.flat()
|
||||
.map(code => {
|
||||
let extraMessages: {
|
||||
let messageBundle: {
|
||||
[languageTag: string]: Record<string, string>;
|
||||
} = {};
|
||||
|
||||
try {
|
||||
eval(`${symToStr({ extraMessages })} = ${code}`);
|
||||
eval(`${symToStr({ messageBundle })} = ${code}`);
|
||||
} catch {
|
||||
console.warn(
|
||||
[
|
||||
@ -94,34 +94,23 @@ export function generateMessageProperties(params: {
|
||||
);
|
||||
}
|
||||
|
||||
return extraMessages;
|
||||
return messageBundle;
|
||||
});
|
||||
|
||||
const languageTags = [
|
||||
...extraMessages.map(extraMessage => Object.keys(extraMessage)).flat(),
|
||||
...fs
|
||||
.readdirSync(
|
||||
pathJoin(
|
||||
getThisCodebaseRootDirPath(),
|
||||
"src",
|
||||
themeType,
|
||||
"i18n",
|
||||
"baseMessages"
|
||||
)
|
||||
)
|
||||
.filter(baseName => baseName !== "index.ts")
|
||||
.map(baseName => baseName.replace(/\.ts$/, ""))
|
||||
].reduce(...removeDuplicates<string>());
|
||||
const languageTags_messageBundle = messageBundles
|
||||
.map(extraMessage => Object.keys(extraMessage))
|
||||
.flat()
|
||||
.reduce(...removeDuplicates<string>());
|
||||
|
||||
const keyValueMapByLanguageTag: Record<string, Record<string, string>> = {};
|
||||
|
||||
for (const languageTag of languageTags) {
|
||||
languageTags_messageBundle.forEach(languageTag_messageBundle => {
|
||||
const keyValueMap: Record<string, string> = {
|
||||
termsText: ""
|
||||
};
|
||||
|
||||
for (const extraMessage of extraMessages) {
|
||||
const keyValueMap_i = extraMessage[languageTag];
|
||||
for (const messageBundle of messageBundles) {
|
||||
const keyValueMap_i = messageBundle[languageTag_messageBundle];
|
||||
|
||||
if (keyValueMap_i === undefined) {
|
||||
continue;
|
||||
@ -151,8 +140,25 @@ export function generateMessageProperties(params: {
|
||||
}
|
||||
}
|
||||
|
||||
keyValueMapByLanguageTag[languageTag] = keyValueMap;
|
||||
}
|
||||
keyValueMapByLanguageTag[languageTag_messageBundle] = keyValueMap;
|
||||
});
|
||||
|
||||
fs.readdirSync(
|
||||
pathJoin(getThisCodebaseRootDirPath(), "src", themeType, "i18n", "baseMessages")
|
||||
)
|
||||
.filter(baseName => baseName !== "index.ts")
|
||||
.map(baseName => baseName.replace(/\.ts$/, ""))
|
||||
.filter(languageTag => !languageTags_messageBundle.includes(languageTag))
|
||||
.forEach(
|
||||
languageTag_noMessageBundle =>
|
||||
(keyValueMapByLanguageTag[languageTag_noMessageBundle] =
|
||||
keyValueMapByLanguageTag[fallbackLanguageTag] ??
|
||||
keyValueMapByLanguageTag[
|
||||
Object.keys(keyValueMapByLanguageTag)[0]
|
||||
] ?? {
|
||||
termsText: ""
|
||||
})
|
||||
);
|
||||
|
||||
const out: { languageTag: string; propertiesFileSource: string }[] = [];
|
||||
|
||||
|
@ -67,3 +67,5 @@ export type LoginThemePageId = (typeof loginThemePageIds)[number];
|
||||
export type AccountThemePageId = (typeof accountThemePageIds)[number];
|
||||
|
||||
export const containerName = "keycloak-keycloakify";
|
||||
|
||||
export const fallbackLanguageTag = "en";
|
||||
|
@ -3,8 +3,7 @@ import { assert } from "tsafe/assert";
|
||||
import messages_fallbackLanguage from "./baseMessages/en";
|
||||
import { getMessages } from "./baseMessages";
|
||||
import type { KcContext } from "../KcContext";
|
||||
|
||||
export const fallbackLanguageTag = "en";
|
||||
import { fallbackLanguageTag } from "keycloakify/bin/shared/constants";
|
||||
|
||||
export type KcContextLike = {
|
||||
locale?: {
|
||||
|
@ -2,4 +2,3 @@ import type { GenericI18n, MessageKey, KcContextLike } from "./i18n";
|
||||
export type { MessageKey, KcContextLike };
|
||||
export type I18n = GenericI18n<MessageKey>;
|
||||
export { createUseI18n } from "./useI18n";
|
||||
export { fallbackLanguageTag } from "./i18n";
|
||||
|
@ -7,12 +7,12 @@ import {
|
||||
} from "./i18n";
|
||||
import { Reflect } from "tsafe/Reflect";
|
||||
|
||||
export function createUseI18n<ExtraMessageKey extends string = never>(extraMessages: {
|
||||
export function createUseI18n<ExtraMessageKey extends string = never>(messageBundle: {
|
||||
[languageTag: string]: { [key in ExtraMessageKey]: string };
|
||||
}) {
|
||||
type I18n = GenericI18n<MessageKey | ExtraMessageKey>;
|
||||
|
||||
const { getI18n } = createGetI18n(extraMessages);
|
||||
const { getI18n } = createGetI18n(messageBundle);
|
||||
|
||||
function useI18n(params: { kcContext: KcContextLike }): { i18n: I18n } {
|
||||
const { kcContext } = params;
|
||||
|
Reference in New Issue
Block a user