Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/docs/website/build
npm-debug.log*
.history
src/lib/forms/locales
73 changes: 48 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,40 @@
"dist"
],
"scripts": {
"start": "react-scripts start",
"build": "rimraf dist && NODE_ENV=production rollup -c --failAfterWarnings --inlineDynamicImports",
"prepare": "node scripts/patch-hugerte-langs.js",
"start": "npm run prepare && react-scripts start",
"build": "npm run prepare && rimraf dist && NODE_ENV=production rollup -c --failAfterWarnings --inlineDynamicImports && node scripts/copy-hugerte-langs.js",
"edit-linked-package": "json -I -f ./dist/package.json -e 'this.module=\"esm/index.js\", this.main=\"cjs/index.js\", this.browser=\"cjs/index.js\"' ",
"prelink-dist": "cp package.json ./dist && npm run edit-linked-package",
"link-dist": "cd dist && npm link",
"postlink-dist": "cd dist && rm -rf node_modules",
"unlink-dist": "cd dist && npm unlink && rm package*",
"watch": "NODE_ENV=development rollup --watch --inlineDynamicImports -c",
"watch": "npm run prepare && NODE_ENV=development rollup --watch --inlineDynamicImports -c",
"test": "react-scripts test",
"eject": "react-scripts eject",
"lint": "eslint src/ --ext .js",
"format": "prettier --config ./.prettierrc --ignore-path ./.prettierignore --write \"src/**/*.js\""
},
"peerDependencies": {
"@babel/runtime": "^7.26.10",
"@hugerte/hugerte-react": "^2.0.2",
"@semantic-ui-react/css-patch": "^1.0.0",
"@tinymce/tinymce-react": "^4.3.0",
"axios": "^1.8.2",
"formik": "^2.1.0",
"hugerte": "^1.0.10",
"lodash": "^4.17.0",
"luxon": "^1.23.0",
"query-string": "^7.0.0",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"react-overridable": "^1.0.0",
"semantic-ui-css": "^2.4.0",
"semantic-ui-react": "^2.1.0",
"tinymce": "^6.7.2",
"react-overridable": "^1.0.0",
"yup": "^0.32.11"
},
"devDependencies": {
"@babel/cli": "^7.5.0",
"@hugerte/hugerte-react": "^2.0.2",
"@inveniosoftware/eslint-config-invenio": "^2.0.0",
"@rollup/plugin-babel": "^5.0.0",
"@rollup/plugin-commonjs": "^11.1.0",
Expand All @@ -49,7 +51,6 @@
"@testing-library/jest-dom": "^4.2.0",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.0",
"@tinymce/tinymce-react": "^4.3.0",
"ajv": "^8.0.0",
"ajv-keywords": "^5.0.0",
"axios": "^1.7.7",
Expand All @@ -58,6 +59,7 @@
"enzyme-adapter-react-16": "^1.15.0",
"expect": "^26.0.0",
"formik": "^2.1.0",
"hugerte": "^1.0.10",
"json": "^10.0.0",
"lodash": "^4.17.0",
"luxon": "^1.23.0",
Expand All @@ -73,7 +75,7 @@
"rollup-plugin-url": "^3.0.0",
"semantic-ui-css": "^2.4.0",
"semantic-ui-react": "^2.1.0",
"tinymce": "^6.7.2",
"tinymce-i18n": "^26.5.18",
"typescript": "^4.9.5",
"yup": "^0.32.11"
},
Expand Down
81 changes: 81 additions & 0 deletions scripts/copy-hugerte-langs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/usr/bin/env node
/**
* Build script to copy patched HugeRTE language packs into dist/hugerte-langs/.
*
* Invenio-supported locales (exact list from invenio-i18n/translations):
* ar, bg, ca, cs, da, de, el, en, es, et, fa, fi, fr, hr, hu, it,
* ja, ka, ko, lt, no, pl, pt, ro, ru, sk, sv, tr, uk, zh_CN, zh_TW
*
* Files are copied with their TinyMCE 6 filenames so RichEditor's mapping works.
*
* Source locale files are the ones already patched by `patch-hugerte-langs.js`
* (tinymce.addI18n -> window.hugerte.addI18n) so they work in bundled strict-mode.
*/

const fs = require("fs");
const path = require("path");

const LOCALES_DIR = path.resolve(__dirname, "../src/lib/forms/locales");
const OUT_DIR = path.resolve(__dirname, "../dist/hugerte-langs");

const invenioLocaleMap = {
ar: "ar",
bg: "bg_BG",
ca: "ca",
cs: "cs",
da: "da",
de: "de",
el: "el",
en: null, // English is the default; no pack needed.
es: "es",
et: "et",
fa: "fa",
fi: "fi",
fr: "fr_FR",
hr: "hr",
hu: "hu_HU",
it: "it",
ja: "ja",
ka: "ka_GE",
ko: "ko_KR",
lt: "lt",
no: "nb_NO",
pl: "pl",
pt: "pt_BR",
ro: "ro",
ru: "ru",
sk: "sk",
sv: "sv_SE",
tr: "tr",
uk: "uk",
zh_CN: "zh-Hans",
zh_TW: "zh-Hant",
};

function main() {
if (!fs.existsSync(LOCALES_DIR)) {
console.error(`patched locales not found at ${LOCALES_DIR}; run 'npm run prepare' first`);
process.exit(1);
}

fs.mkdirSync(OUT_DIR, { recursive: true });

for (const [invenioCode, tinymceCode] of Object.entries(invenioLocaleMap)) {
if (!tinymceCode) continue;

const src = path.join(LOCALES_DIR, `${tinymceCode}.js`);
const dest = path.join(OUT_DIR, `${tinymceCode}.js`);

if (!fs.existsSync(src)) {
console.warn(`Missing language pack: ${src} (Invenio: ${invenioCode}, TinyMCE: ${tinymceCode})`);
continue;
}

fs.copyFileSync(src, dest);
console.log(`Copied ${tinymceCode}.js`);
}

console.log("Done.");
}

main();
31 changes: 31 additions & 0 deletions scripts/patch-hugerte-langs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");

const SRC_DIR = path.resolve(__dirname, "../node_modules/tinymce-i18n/langs6");
const OUT_DIR = path.resolve(__dirname, "../src/lib/forms/locales");

const locales = [
"ar", "bg_BG", "ca", "cs", "da", "de", "el", "es", "et", "fa", "fi",
"fr_FR", "hr", "hu_HU", "it", "ja", "ka_GE", "ko_KR", "lt", "nb_NO",
"pl", "pt_BR", "ro", "ru", "sk", "sv_SE", "tr", "uk", "zh-Hans", "zh-Hant",
];

fs.mkdirSync(OUT_DIR, { recursive: true });

for (const code of locales) {
const src = path.join(SRC_DIR, `${code}.js`);
const dest = path.join(OUT_DIR, `${code}.js`);
if (!fs.existsSync(src)) {
console.warn(`missing ${src}`);
continue;
}
let text = fs.readFileSync(src, "utf-8");
// HugeRTE docs: replace `tinymce` variable by `hugerte`.
// Use `window.hugerte` so it works in bundled strict-mode output.
text = text.replace(/\btinymce\.addI18n\(/g, "window.hugerte.addI18n(");
fs.writeFileSync(dest, text);
console.log(`patched ${code}.js`);
}

console.log("done.");
Loading
Loading