Automatically generate account i18n code

This commit is contained in:
Joseph Garrone 2024-09-21 21:39:08 +02:00
parent cc700f0ba0
commit e8d3d3d741
3 changed files with 29 additions and 2 deletions

2
.gitignore vendored
View File

@ -49,7 +49,7 @@ jspm_packages
.idea .idea
/src/login/i18n/messages_defaultSet/ /src/login/i18n/messages_defaultSet/
/src/account/i18n/messages_defaultSet/ /src/account/i18n/
# VS Code devcontainers # VS Code devcontainers
.devcontainer .devcontainer

View File

@ -23,6 +23,17 @@ if (require.main === module) {
async function generateI18nMessages() { async function generateI18nMessages() {
const thisCodebaseRootDirPath = getThisCodebaseRootDirPath(); const thisCodebaseRootDirPath = getThisCodebaseRootDirPath();
const accountI18nDirPath = pathJoin(
thisCodebaseRootDirPath,
"src",
"account",
"i18n"
);
if (fs.existsSync(accountI18nDirPath)) {
fs.rmSync(accountI18nDirPath, { recursive: true });
}
type Dictionary = { [idiomId: string]: string }; type Dictionary = { [idiomId: string]: string };
const record: { [themeType: string]: { [language: string]: Dictionary } } = {}; const record: { [themeType: string]: { [language: string]: Dictionary } } = {};
@ -140,6 +151,10 @@ async function generateI18nMessages() {
"messages_defaultSet" "messages_defaultSet"
); );
if (!fs.existsSync(messagesDirPath)) {
fs.mkdirSync(messagesDirPath, { recursive: true });
}
fs.writeFileSync( fs.writeFileSync(
pathJoin(messagesDirPath, "types.ts"), pathJoin(messagesDirPath, "types.ts"),
Buffer.from( Buffer.from(
@ -219,6 +234,18 @@ async function generateI18nMessages() {
) )
); );
} }
transformCodebase({
srcDirPath: pathJoin(thisCodebaseRootDirPath, "src", "login", "i18n"),
destDirPath: accountI18nDirPath,
transformSourceCode: ({ fileRelativePath, sourceCode }) => {
if (fileRelativePath.startsWith("messages_defaultSet")) {
return undefined;
}
return { modifiedSourceCode: sourceCode };
}
});
} }
const keycloakifyExtraMessages_login: Record< const keycloakifyExtraMessages_login: Record<

View File

@ -1,7 +1,7 @@
import type { import type {
LanguageTag as LanguageTag_defaultSet, LanguageTag as LanguageTag_defaultSet,
MessageKey as MessageKey_defaultSet MessageKey as MessageKey_defaultSet
} from "keycloakify/login/i18n/messages_defaultSet/types"; } from "../messages_defaultSet/types";
import { type ReturnTypeOfCreateGetI18n, createGetI18n } from "./getI18n"; import { type ReturnTypeOfCreateGetI18n, createGetI18n } from "./getI18n";
export type I18nInitializer< export type I18nInitializer<