New i18n with dynamic imports

This commit is contained in:
garronej
2022-07-31 18:57:30 +02:00
parent 2be40816b2
commit 69c15bd473
34 changed files with 135 additions and 32032 deletions

View File

@ -1,6 +1,6 @@
import "minimal-polyfills/Object.fromEntries";
import * as fs from "fs";
import { join as pathJoin, relative as pathRelative } from "path";
import { join as pathJoin, relative as pathRelative, dirname as pathDirname } from "path";
import { crawl } from "./tools/crawl";
import { downloadBuiltinKeycloakTheme } from "./download-builtin-keycloak-theme";
import { getProjectRoot } from "./tools/getProjectRoot";
@ -50,28 +50,32 @@ for (const keycloakVersion of ["11.0.3", "15.0.2", "18.0.1"]) {
rm_r(tmpDirPath);
const targetDirPath = pathJoin(getProjectRoot(), "src", "lib", "i18n", "generated_kcMessages", keycloakVersion);
fs.mkdirSync(targetDirPath, { "recursive": true });
Object.keys(record).forEach(pageType => {
const filePath = pathJoin(targetDirPath, `${pageType}.ts`);
const recordForPageType = record[pageType];
fs.writeFileSync(
filePath,
Buffer.from(
[
`//This code was automatically generated by running ${pathRelative(getProjectRoot(), __filename)}`,
"//PLEASE DO NOT EDIT MANUALLY",
"",
"/* spell-checker: disable */",
`export const kcMessages= ${JSON.stringify(record[pageType], null, 2)};`,
"/* spell-checker: enable */",
].join("\n"),
"utf8",
),
);
Object.keys(recordForPageType).forEach(language => {
const filePath = pathJoin(getProjectRoot(), "src", "lib", "i18n", "generated_kcMessages", keycloakVersion, pageType, `${language}.ts`);
console.log(`${filePath} wrote`);
fs.mkdirSync(pathDirname(filePath), { "recursive": true });
fs.writeFileSync(
filePath,
Buffer.from(
[
`//This code was automatically generated by running ${pathRelative(getProjectRoot(), __filename)}`,
"//PLEASE DO NOT EDIT MANUALLY",
"",
"/* spell-checker: disable */",
`const messages= ${JSON.stringify(recordForPageType[language], null, 2)};`,
"",
"export default messages;",
"/* spell-checker: enable */",
].join("\n"),
"utf8",
),
);
console.log(`${filePath} wrote`);
});
});
}