diff --git a/invenio_rdm_records/assets/semantic-ui/translations/invenio_rdm_records/scripts/compileCatalog.js b/invenio_rdm_records/assets/semantic-ui/translations/invenio_rdm_records/scripts/compileCatalog.js index 1da04f208..e70b856fe 100644 --- a/invenio_rdm_records/assets/semantic-ui/translations/invenio_rdm_records/scripts/compileCatalog.js +++ b/invenio_rdm_records/assets/semantic-ui/translations/invenio_rdm_records/scripts/compileCatalog.js @@ -4,7 +4,7 @@ // Invenio RDM is free software; you can redistribute it and/or modify it // under the terms of the MIT License; see LICENSE file for more details. -const { readFileSync, writeFileSync } = require("fs"); +const { readFileSync, writeFileSync, existsSync } = require("fs"); const { gettextToI18next } = require("i18next-conv"); const PACKAGE_JSON_BASE_PATH = "./"; @@ -13,7 +13,7 @@ const { languages } = require(`../package`).config; // it accepts the same options as the cli. // https://github.com/i18next/i18next-gettext-converter#options const options = { - /* you options here */ + /* your options here */ }; function save(target) { @@ -24,17 +24,31 @@ function save(target) { if ("lang" === process.argv[2]) { const lang = process.argv[3]; - gettextToI18next( - lang, - readFileSync(`${PACKAGE_JSON_BASE_PATH}messages/${lang}/messages.po`), - options - ).then(save(`${PACKAGE_JSON_BASE_PATH}messages/${lang}/translations.json`)); + const inputFilePath = `${PACKAGE_JSON_BASE_PATH}messages/${lang}/messages.po`; + const outputFilePath = `${PACKAGE_JSON_BASE_PATH}messages/${lang}/translations.json`; + + if (existsSync(inputFilePath)) { + gettextToI18next(lang, readFileSync(inputFilePath), options) + .then(save(outputFilePath)) + .catch((err) => { + console.error(`Error converting ${inputFilePath}:`, err); + }); + } else { + console.error(`File not found: ${inputFilePath} for language ${lang}`); + } } else { for (const lang of languages) { - gettextToI18next( - lang, - readFileSync(`${PACKAGE_JSON_BASE_PATH}messages/${lang}/messages.po`), - options - ).then(save(`${PACKAGE_JSON_BASE_PATH}messages/${lang}/translations.json`)); + const inputFilePath = `${PACKAGE_JSON_BASE_PATH}messages/${lang}/messages.po`; + const outputFilePath = `${PACKAGE_JSON_BASE_PATH}messages/${lang}/translations.json`; + + if (existsSync(inputFilePath)) { + gettextToI18next(lang, readFileSync(inputFilePath), options) + .then(save(outputFilePath)) + .catch((err) => { + console.error(`Error converting ${inputFilePath}:`, err); + }); + } else { + console.error(`File not found: ${inputFilePath} for language ${lang}`); + } } }