Skip to content

Commit 3deba89

Browse files
mesemustmorrell
authored andcommitted
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 <miroslav.simek@cesnet.cz>
1 parent 608f5fa commit 3deba89

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

invenio_stats/errors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
"""Errors used in Invenio-Stats."""
1111

12+
from invenio_i18n import gettext as _
1213
from invenio_rest.errors import RESTException
1314

1415
##
@@ -71,6 +72,6 @@ def __init__(self, query_name):
7172
"""
7273
super(RESTException, self).__init__()
7374
self.query_name = query_name
74-
self.description = "Unknown statistic '{}'".format(query_name)
75+
self.description = _("Unknown statistic '{}'").format(query_name)
7576

7677
code = 400

invenio_stats/views.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"""InvenioStats views."""
1010

1111
from flask import Blueprint, abort, jsonify, request
12+
from invenio_i18n import gettext as _
1213
from invenio_rest.views import ContentNegotiatedMethodView
1314
from invenio_search.engine import search
1415

@@ -38,7 +39,7 @@ def __init__(self, **kwargs):
3839
"GET": "application/json",
3940
},
4041
default_media_type="application/json",
41-
**kwargs
42+
**kwargs,
4243
)
4344

4445
def post(self, **kwargs):
@@ -60,9 +61,11 @@ def post(self, **kwargs):
6061
# 'config' has to be a dictionary with mandatory 'stat' key and
6162
# optional 'params' key, and nothing else
6263
raise InvalidRequestInputError(
63-
"Invalid Input. It should be of the form "
64-
'{ STATISTIC_NAME: { "stat": STAT_TYPE, '
65-
'"params": STAT_PARAMS }}'
64+
_(
65+
"Invalid Input. It should be of the form "
66+
'{ STATISTIC_NAME: { "stat": STAT_TYPE, '
67+
'"params": STAT_PARAMS }}'
68+
)
6669
)
6770

6871
stat = config["stat"]
@@ -74,11 +77,11 @@ def post(self, **kwargs):
7477

7578
permission = current_stats.permission_factory(stat, params)
7679
if permission is not None and not permission.can():
77-
message = (
80+
message = _(
7881
"You do not have a permission to query the "
7982
'statistic "{}" with those '
80-
"parameters".format(stat)
81-
)
83+
"parameters"
84+
).format(stat)
8285

8386
if current_user.is_authenticated:
8487
abort(403, message)

tests/test_aggregations.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"""Aggregation tests."""
1010

1111
import datetime
12-
from turtle import pd
1312
from unittest.mock import patch
1413

1514
import pytest

0 commit comments

Comments
 (0)