From d3187047523875c0c9dcda57cfa4bbf50ca8e4b7 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Sat, 26 Oct 2024 02:18:08 +0200 Subject: [PATCH 1/7] i18n: add translations missing entry point --- setup.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.cfg b/setup.cfg index 534bdc6..06c5f8b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2015-2018 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -73,6 +74,8 @@ invenio_pidstore.minters = oaiid = invenio_oaiserver.minters:oaiid_minter invenio_pidstore.fetchers = oaiid = invenio_oaiserver.fetchers:oaiid_fetcher +invenio_i18n.translations = + invenio_oaiserver = invenio_oaiserver [build_sphinx] source-dir = docs/ From 47a2c29c4e9cc97c5c2148054e7f9e447da0ba44 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Mon, 28 Oct 2024 15:30:23 +0100 Subject: [PATCH 2/7] i18n: use gettext for translatable strings in admin * Replaced the custom _ function with gettext from invenio_i18n to standardize internationalization and make translatable strings compatible with Invenio's i18n --- invenio_oaiserver/admin.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/invenio_oaiserver/admin.py b/invenio_oaiserver/admin.py index 25b7378..a34cc1d 100644 --- a/invenio_oaiserver/admin.py +++ b/invenio_oaiserver/admin.py @@ -2,6 +2,7 @@ # # This file is part of Invenio. # Copyright (C) 2015-2018 CERN. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -9,15 +10,11 @@ """Admin model views for OAI sets.""" from flask_admin.contrib.sqla import ModelView +from invenio_i18n import gettext as _ from .models import OAISet -def _(x): - """Identity.""" - return x - - class OAISetModelView(ModelView): """OAISets model view.""" From 8dfd3985308e8761a255d6ff1110cd625ebef906 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Mon, 28 Oct 2024 15:34:14 +0100 Subject: [PATCH 3/7] i18n: add translation for models.py --- invenio_oaiserver/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/invenio_oaiserver/models.py b/invenio_oaiserver/models.py index c370cc7..1b5dba9 100644 --- a/invenio_oaiserver/models.py +++ b/invenio_oaiserver/models.py @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2015-2022 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -79,7 +80,7 @@ class OAISet(db.Model, Timestamp): def validate_spec(self, key, value): """Forbit updates of set identifier.""" if self.spec and self.spec != value: - raise OAISetSpecUpdateError("Updating spec is not allowed.") + raise OAISetSpecUpdateError(_("Updating spec is not allowed.")) return value From 0489c0d8c0d6ed1733f1bdfe4a0ec3199e762820 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Mon, 28 Oct 2024 15:40:17 +0100 Subject: [PATCH 4/7] i18n: add translation for percolator.py --- invenio_oaiserver/percolator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/invenio_oaiserver/percolator.py b/invenio_oaiserver/percolator.py index 86631c8..fa334b8 100644 --- a/invenio_oaiserver/percolator.py +++ b/invenio_oaiserver/percolator.py @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2017-2024 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -12,6 +13,7 @@ import json from flask import current_app +from invenio_i18n import lazy_gettext as _ from invenio_indexer.api import RecordIndexer from invenio_search import current_search, current_search_client from invenio_search.engine import search @@ -128,7 +130,9 @@ def create_percolate_query( ) else: raise Exception( - "Either documents or (document_search_ids and document_search_indices) must be specified." + _( + "Either documents or (document_search_ids and document_search_indices) must be specified." + ) ) if percolator_ids: From e2f644a704cd3424798507e3383440ddd1316fd3 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Mon, 28 Oct 2024 15:49:33 +0100 Subject: [PATCH 5/7] i18n: add translation for verbs.py --- invenio_oaiserver/verbs.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/invenio_oaiserver/verbs.py b/invenio_oaiserver/verbs.py index ebb3994..93ebbde 100644 --- a/invenio_oaiserver/verbs.py +++ b/invenio_oaiserver/verbs.py @@ -4,6 +4,7 @@ # Copyright (C) 2015-2018 CERN. # Copyright (C) 2021-2022 Graz University of Technology. # Copyright (C) 2022 RERO. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -11,6 +12,7 @@ """OAI-PMH verbs.""" from flask import current_app, request +from invenio_i18n import lazy_gettext as _ from invenio_rest.serializer import BaseSchema from marshmallow import ValidationError, fields, validates_schema from marshmallow.fields import DateTime as _DateTime @@ -28,7 +30,7 @@ def validate_metadata_prefix(value, **kwargs): metadataFormats = current_app.config["OAISERVER_METADATA_FORMATS"] if value not in metadataFormats: raise ValidationError( - "metadataPrefix does not exist", field_names=["metadataPrefix"] + _("metadataPrefix does not exist"), field_names=["metadataPrefix"] ) @@ -88,12 +90,13 @@ def validate(self, data, **kwargs): if "verb" in data and data["verb"] != self.__class__.__name__: raise ValidationError( # FIXME encode data - "This is not a valid OAI-PMH verb:{0}".format(data["verb"]), + _("This is not a valid OAI-PMH verb:{0}").format(data["verb"]), field_names=["verb"], ) if "from_" in data and "until" in data and data["from_"] > data["until"]: - raise ValidationError('Date "from" must be before "until".') + + raise ValidationError(_('Date "from" must be before "until".')) class Verbs(object): @@ -162,7 +165,7 @@ def check_extra_params_in_request(verb): ] ) if extra: - raise ValidationError({"_schema": ["You have passed too many arguments."]}) + raise ValidationError({"_schema": [_("You have passed too many arguments.")]}) def make_request_validator(request): From 52a78ffc24876c73ee93f359e439572e513a03f6 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Mon, 28 Oct 2024 15:53:55 +0100 Subject: [PATCH 6/7] CI: switch to centralized workflows --- .github/workflows/tests.yml | 66 +++++-------------------------------- 1 file changed, 9 insertions(+), 57 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8ef8bfd..a3f80b8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2020 CERN. # Copyright (C) 2022 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio is free software; you can redistribute it and/or modify it # under the terms of the MIT License; see LICENSE file for more details. @@ -11,9 +12,11 @@ name: CI on: push: - branches: master + branches: + - master pull_request: - branches: master + branches: + - master schedule: # * is a special character in YAML so you have to quote this string - cron: '0 3 * * 6' @@ -25,58 +28,7 @@ on: default: 'Manual trigger' jobs: - Tests: - runs-on: ubuntu-20.04 - timeout-minutes: 20 - strategy: - matrix: - python-version: [3.8, 3.9] - requirements-level: [pypi] - db-service: [postgresql14,postgresql13,mysql8] - mq-service: [rabbitmq] - search-service: [opensearch2,elasticsearch7] - include: - - db-service: postgresql14 - DB_EXTRAS: "postgresql" - - - db-service: postgresql13 - DB_EXTRAS: "postgresql" - - - db-service: mysql8 - DB_EXTRAS: "mysql" - env: - DB: ${{ matrix.db-service }} - MQ: ${{ matrix.mq-service }} - SEARCH: ${{ matrix.search-service }} - EXTRAS: tests,${{ matrix.search-service }} - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - - name: Generate dependencies - run: | - pip install wheel requirements-builder - requirements-builder -e "$EXTRAS" --level=${{ matrix.requirements-level }} setup.py > .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt - - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-${{ hashFiles('.${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt') }} - - - name: Install dependencies - run: | - pip install -r .${{ matrix.requirements-level }}-${{ matrix.python-version }}-requirements.txt - pip install ".[$EXTRAS]" - pip freeze - docker --version - docker compose --version - - - name: Run tests - run: | - ./run-tests.sh + Python: + uses: inveniosoftware/workflows/.github/workflows/tests-python.yml@master + with: + extras: "tests" From f22f1edc8b6a36c0251b6ca2bf3d697bf8f0a74e Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Mon, 28 Oct 2024 16:01:54 +0100 Subject: [PATCH 7/7] i18n: use get_text instead of lazy --- invenio_oaiserver/verbs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/invenio_oaiserver/verbs.py b/invenio_oaiserver/verbs.py index 93ebbde..9119c3f 100644 --- a/invenio_oaiserver/verbs.py +++ b/invenio_oaiserver/verbs.py @@ -12,7 +12,7 @@ """OAI-PMH verbs.""" from flask import current_app, request -from invenio_i18n import lazy_gettext as _ +from invenio_i18n import gettext as _ from invenio_rest.serializer import BaseSchema from marshmallow import ValidationError, fields, validates_schema from marshmallow.fields import DateTime as _DateTime