From c727a28ce281c315b70af5051fa7082798e5bd30 Mon Sep 17 00:00:00 2001 From: Mirek Simek Date: Tue, 10 Dec 2024 15:38:03 +0100 Subject: [PATCH] i18n: Fix untranslated strings in views and errors There are untranslated permission and usage errors in views.py and errors.py. This commit fixes those by using `gettext` from invenio-i18n. Co-authored-by: Miroslav Simek --- invenio_stats/errors.py | 3 ++- invenio_stats/views.py | 17 ++++++++++------- tests/test_aggregations.py | 1 - 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/invenio_stats/errors.py b/invenio_stats/errors.py index 50e1b9a..5e623f6 100644 --- a/invenio_stats/errors.py +++ b/invenio_stats/errors.py @@ -9,6 +9,7 @@ """Errors used in Invenio-Stats.""" +from invenio_i18n import gettext as _ from invenio_rest.errors import RESTException ## @@ -71,6 +72,6 @@ def __init__(self, query_name): """ super(RESTException, self).__init__() self.query_name = query_name - self.description = "Unknown statistic '{}'".format(query_name) + self.description = _("Unknown statistic '{}'").format(query_name) code = 400 diff --git a/invenio_stats/views.py b/invenio_stats/views.py index 76d6ac7..ee129e0 100644 --- a/invenio_stats/views.py +++ b/invenio_stats/views.py @@ -9,6 +9,7 @@ """InvenioStats views.""" from flask import Blueprint, abort, jsonify, request +from invenio_i18n import gettext as _ from invenio_rest.views import ContentNegotiatedMethodView from invenio_search.engine import search @@ -38,7 +39,7 @@ def __init__(self, **kwargs): "GET": "application/json", }, default_media_type="application/json", - **kwargs + **kwargs, ) def post(self, **kwargs): @@ -60,9 +61,11 @@ def post(self, **kwargs): # 'config' has to be a dictionary with mandatory 'stat' key and # optional 'params' key, and nothing else raise InvalidRequestInputError( - "Invalid Input. It should be of the form " - '{ STATISTIC_NAME: { "stat": STAT_TYPE, ' - '"params": STAT_PARAMS }}' + _( + "Invalid Input. It should be of the form " + '{ STATISTIC_NAME: { "stat": STAT_TYPE, ' + '"params": STAT_PARAMS }}' + ) ) stat = config["stat"] @@ -74,11 +77,11 @@ def post(self, **kwargs): permission = current_stats.permission_factory(stat, params) if permission is not None and not permission.can(): - message = ( + message = _( "You do not have a permission to query the " 'statistic "{}" with those ' - "parameters".format(stat) - ) + "parameters" + ).format(stat) if current_user.is_authenticated: abort(403, message) diff --git a/tests/test_aggregations.py b/tests/test_aggregations.py index 24c25bc..2cfba1f 100644 --- a/tests/test_aggregations.py +++ b/tests/test_aggregations.py @@ -9,7 +9,6 @@ """Aggregation tests.""" import datetime -from turtle import pd from unittest.mock import patch import pytest