diff --git a/invenio_cli/commands/local.py b/invenio_cli/commands/local.py index a6b96d5..d225b80 100644 --- a/invenio_cli/commands/local.py +++ b/invenio_cli/commands/local.py @@ -2,6 +2,7 @@ # # Copyright (C) 2020 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2025 TUBITAK ULAKBIM # # Invenio-Cli is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -87,6 +88,17 @@ def update_statics_and_assets(self, force, debug=False, log_file=None): pkg_man = self.cli_config.python_package_manager ops = [pkg_man.run_command("invenio", "collect", "--verbose")] + js_translations_bundle_path = self.cli_config.get_js_translations_bundle_path() + ops.append( + pkg_man.run_command( + "invenio", + "i18n", + "distribute-js-translations", + "-i", + js_translations_bundle_path, + ) + ) + if force: ops.append(pkg_man.run_command("invenio", "webpack", "clean", "create")) ops.append(pkg_man.run_command("invenio", "webpack", "install")) diff --git a/invenio_cli/helpers/cli_config.py b/invenio_cli/helpers/cli_config.py index 46e1092..364603f 100644 --- a/invenio_cli/helpers/cli_config.py +++ b/invenio_cli/helpers/cli_config.py @@ -4,12 +4,14 @@ # Copyright (C) 2019-2020 Northwestern University. # Copyright (C) 2021 Esteban J. G. Gabancho. # Copyright (C) 2024 Graz University of Technology. +# Copyright (C) 2025 TUBITAK ULAKBIM # # Invenio-Cli is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. """Invenio-cli configuration file.""" +import os from configparser import ConfigParser from pathlib import Path @@ -59,6 +61,8 @@ def __init__(self, project_dir="./"): self.private_config.read_file(cfg_file) except FileNotFoundError: CLIConfig._write_private_config(Path(project_dir)) + # TODO: change js translations directory + os.mkdir(f"{project_dir}/js_translations") with open(self.private_config_path) as cfg_file: self.private_config.read_file(cfg_file) @@ -97,6 +101,20 @@ def get_instance_path(self, throw=True): elif throw: raise InvenioCLIConfigError("Accessing unset 'instance_path'") + def get_js_translations_bundle_path(self, throw=True): + """Returns path to translation bundle directory. + + If not set yet, raises an InvenioCLIConfigError. + """ + # TODO: config name may change + path = self.private_config[CLIConfig.CLI_SECTION].get( + "js_translations_bundle_path" + ) + if path: + return Path(path) + elif throw: + raise InvenioCLIConfigError("Accessing unset 'js_translations_bundle_path'") + def update_instance_path(self, new_instance_path): """Updates path to application instance directory.""" self.private_config[CLIConfig.CLI_SECTION]["instance_path"] = str( @@ -187,6 +205,10 @@ def _write_private_config(cls, project_dir): config_parser = ConfigParser() config_parser[cls.CLI_SECTION] = {} config_parser[cls.CLI_SECTION]["services_setup"] = str(False) + # TODO: change js translations directory + config_parser[cls.CLI_SECTION][ + "js_translations_bundle_path" + ] = f"{project_dir}/js_translations" private_config_path = project_dir / cls.PRIVATE_CONFIG_FILENAME with open(private_config_path, "w") as configfile: config_parser.write(configfile) @@ -224,4 +246,8 @@ def write(cls, project_dir, flavour, replay): # Custom to machine (not version controlled) cls._write_private_config(project_dir) + # Create js translations directory + # TODO: change js translations directory + os.mkdir(f"{project_dir}/js_translations") + return project_dir