From 88af7fff8465d789658f418dfa14ed9e0ebc4fee Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Tue, 1 Oct 2024 20:32:34 +0200 Subject: [PATCH 1/2] i18n: Improve handling of file existence check in compileCatalog * Add a check for the existence of the file before attempting to read it * Log an error message if the file does not exist * Improve readability by extracting the file existence check into a function --- .../scripts/compileCatalog.js | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) 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..252c68606 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 @@ -1,10 +1,11 @@ // This file is part of InvenioRdmRecords // Copyright (C) 2022 CERN. +// Copyright (C) 2024 KTH Royal Institute of Technology. // // 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 +14,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 +25,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}`); + } } } From 59ef29050a9cf23e5e8bf1fd0f41c0584c8b311c Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Sun, 2 Feb 2025 13:21:01 +0100 Subject: [PATCH 2/2] chores: isort and black formatting --- invenio_rdm_records/services/communities/components.py | 4 +++- tests/services/schemas/test_version.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/invenio_rdm_records/services/communities/components.py b/invenio_rdm_records/services/communities/components.py index 8c2f4c5a9..d730f7f28 100644 --- a/invenio_rdm_records/services/communities/components.py +++ b/invenio_rdm_records/services/communities/components.py @@ -8,7 +8,9 @@ """Record communities service components.""" from invenio_communities.communities.records.systemfields.access import VisibilityEnum -from invenio_communities.communities.services.components import ChildrenComponent +from invenio_communities.communities.services.components import ( + ChildrenComponent, +) from invenio_communities.communities.services.components import ( CommunityAccessComponent as BaseAccessComponent, ) diff --git a/tests/services/schemas/test_version.py b/tests/services/schemas/test_version.py index 21e5bae8c..1e0c3ea72 100644 --- a/tests/services/schemas/test_version.py +++ b/tests/services/schemas/test_version.py @@ -13,7 +13,7 @@ from invenio_rdm_records.services.schemas.metadata import MetadataSchema -@pytest.mark.parametrize("version", [("v1.0.0")]) +@pytest.mark.parametrize("version", ["v1.0.0"]) def test_valid_version(version, app, minimal_record): metadata = minimal_record["metadata"] metadata["version"] = version