Skip to content

Commit 5b141f0

Browse files
committed
Bundle the translations from the bundled plugins
1 parent 32303f4 commit 5b141f0

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

release.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
npm run build
33
cp dist/ckeditor5.umd.js ../WCF/wcfsetup/install/files/js/3rdParty/ckeditor/ckeditor5.bundle.js
44
cp dist/ckeditor5.css ../WCF/wcfsetup/install/files/style/
5-
#cp dist/translations/*.js ../WCF/wcfsetup/install/files/js/3rdParty/ckeditor/translations/
5+
cp dist/translations/*.js ../WCF/wcfsetup/install/files/js/3rdParty/ckeditor/translations/

vite.config.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,61 @@
11
import { defineConfig } from "vite";
2+
import { existsSync } from "fs";
3+
import { mkdir, readdir, readFile, writeFile } from "fs/promises";
4+
import { resolve } from "path";
5+
6+
function ckeditorTranslations() {
7+
return {
8+
name: "ckeditor5-translations",
9+
async writeBundle(options) {
10+
const outDir = options.dir || "dist";
11+
const targetDir = resolve(outDir, "translations");
12+
13+
// Parse app.ts to find all @ckeditor/ckeditor5-* packages.
14+
const appSource = await readFile("app.ts", "utf-8");
15+
const packages = [
16+
...new Set(
17+
[...appSource.matchAll(/@ckeditor\/(ckeditor5-[a-z-]+)/g)].map(
18+
(m) => m[1],
19+
),
20+
),
21+
];
22+
23+
// Collect the translation directories that exist for these packages.
24+
const translationDirs = packages
25+
.map((pkg) =>
26+
resolve("node_modules/@ckeditor", pkg, "dist/translations"),
27+
)
28+
.filter((dir) => existsSync(dir));
29+
30+
// Determine available languages from the first directory.
31+
const languages = (await readdir(translationDirs[0]))
32+
.filter((f) => f.endsWith(".umd.js") && f !== "en.umd.js")
33+
.map((f) => f.replace(".umd.js", ""));
34+
35+
await mkdir(targetDir, { recursive: true });
36+
37+
// For each language, concatenate the translation files from all packages.
38+
await Promise.all(
39+
languages.map(async (lang) => {
40+
const parts = await Promise.all(
41+
translationDirs.map(async (dir) => {
42+
const file = resolve(dir, `${lang}.umd.js`);
43+
if (existsSync(file)) {
44+
return readFile(file, "utf-8");
45+
}
46+
return "";
47+
}),
48+
);
49+
50+
await writeFile(
51+
resolve(targetDir, `${lang}.js`),
52+
parts.filter(Boolean).join("\n"),
53+
);
54+
}),
55+
);
56+
},
57+
};
58+
}
259

360
export default defineConfig({
461
build: {
@@ -9,4 +66,5 @@ export default defineConfig({
966
name: "ckeditor5",
1067
},
1168
},
69+
plugins: [ckeditorTranslations()],
1270
});

0 commit comments

Comments
 (0)