Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n: Mark Missing Translations #313

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions invenio_files_rest/storage/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2016-2019 CERN.
# Copyright © 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.
Expand All @@ -12,6 +13,8 @@
from calendar import timegm
from functools import partial

from invenio_i18n import gettext as _

from ..errors import FileSizeError, StorageError, UnexpectedFileSizeError
from ..helpers import chunk_size_or_default, compute_checksum, send_stream

Expand All @@ -29,15 +32,15 @@ def check_sizelimit(size_limit, bytes_written, total_size):
"""
if size_limit is not None and bytes_written > size_limit:
desc = (
"File size limit exceeded."
_("File size limit exceeded.")
if isinstance(size_limit, int)
else size_limit.reason
)
raise FileSizeError(description=desc)

# Never write more than advertised
if total_size is not None and bytes_written > total_size:
raise UnexpectedFileSizeError(description="File is bigger than expected.")
raise UnexpectedFileSizeError(description=_("File is bigger than expected."))


def check_size(bytes_written, total_size):
Expand All @@ -49,7 +52,7 @@ def check_size(bytes_written, total_size):
written exceed the total size.
"""
if total_size and bytes_written < total_size:
raise UnexpectedFileSizeError(description="File is smaller than expected.")
raise UnexpectedFileSizeError(description=_("File is smaller than expected."))


class FileStorage(object):
Expand Down Expand Up @@ -114,7 +117,7 @@ def send_file(
try:
fp = self.open(mode="rb")
except Exception as e:
raise StorageError("Could not send file: {}".format(e))
raise StorageError(_("Could not send file: {error}").format(error=e))

try:
md5_checksum = None
Expand All @@ -139,7 +142,7 @@ def send_file(
)
except Exception as e:
fp.close()
raise StorageError("Could not send file: {}".format(e))
raise StorageError(_("Could not send file: {error}").format(error=e))

def checksum(self, chunk_size=None, progress_callback=None, **kwargs):
"""Compute checksum of file."""
Expand Down Expand Up @@ -206,7 +209,9 @@ def _compute_checksum(
**kwargs
)
except Exception as e:
raise StorageError("Could not compute checksum of file: {0}".format(e))
raise StorageError(
_("Could not compute checksum of file: {error}").format(error=e)
)

def _write_stream(
self,
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ invenio_db.alembic =
invenio_files_rest = invenio_files_rest:alembic
invenio_db.models =
invenio_files_rest = invenio_files_rest.models
invenio_i18n.translations =
invenio_files_rest = invenio_files_rest

[build_sphinx]
source-dir = docs/
Expand Down