From 71e74113c3b4738bd933d0b7b4459b446acc2871 Mon Sep 17 00:00:00 2001 From: Sam Arbid Date: Sat, 19 Oct 2024 17:46:56 +0200 Subject: [PATCH] i18n: mark translations for end user msgs --- invenio_communities/communities/schema.py | 4 +-- .../communities/services/components.py | 17 +++++++------ .../communities/services/service.py | 4 ++- .../members/resources/config.py | 5 ++-- .../members/services/components.py | 8 +++--- .../members/services/fields.py | 3 ++- invenio_communities/roles.py | 7 ++++-- .../subcommunities/services/schema.py | 4 ++- invenio_communities/views/communities.py | 25 +++++++++---------- 9 files changed, 45 insertions(+), 32 deletions(-) diff --git a/invenio_communities/communities/schema.py b/invenio_communities/communities/schema.py index 1db36a74a..a6cf7892f 100644 --- a/invenio_communities/communities/schema.py +++ b/invenio_communities/communities/schema.py @@ -321,8 +321,8 @@ class CommunityFeaturedSchema(Schema): id = fields.Int(dump_only=True) start_date = fields.DateTime( required=True, - title="start date", - description="Accepted format: YYYY-MM-DD hh:mm", + title=_("start date"), + description=_("Accepted format: YYYY-MM-DD hh:mm"), placeholder="YYYY-MM-DD hh:mm", ) diff --git a/invenio_communities/communities/services/components.py b/invenio_communities/communities/services/components.py index 4c5bdebba..d76c73b53 100644 --- a/invenio_communities/communities/services/components.py +++ b/invenio_communities/communities/services/components.py @@ -4,6 +4,7 @@ # Copyright (C) 2016-2024 CERN. # Copyright (C) 2022 Northwestern University. # Copyright (C) 2022-2023 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. @@ -160,7 +161,7 @@ def _create_set_spec(self, community_slug): def _create_set_description(self, community_title): # NOTE: Does not require translation since this description can also be changed by an admin - return "Records belonging to the community '{title}'".format( + return _("Records belonging to the community '{title}'").format( title=community_title ) @@ -173,7 +174,7 @@ def _create_set_from_community(self, record): community_set.system_created = True community_set.description = self._create_set_description(community_title) community_set.spec = self._create_set_spec(community_slug) - community_set.search_pattern = "parent.communities.ids:{id}".format( + community_set.search_pattern = _("parent.communities.ids:{id}").format( id=record.id ) @@ -315,21 +316,23 @@ def _validate_and_get_parent(self, parent_data, child): try: parent = self.service.record_cls.pid.resolve(parent_data["id"]) if not parent.children.allow: - raise ValidationError("Assigned parent is not allowed to be a parent.") + raise ValidationError( + _("Assigned parent is not allowed to be a parent.") + ) elif child.children.allow: raise ValidationError( - "Community allowed to be a parent can't be a child." + _("Community allowed to be a parent can't be a child.") ) elif parent.parent: raise ValidationError( - "Assigned parent community cannot also have a parent." + _("Assigned parent community cannot also have a parent.") ) elif child.id == parent.id: raise ValidationError( - "Assigned parent community cannot be the same as child." + _("Assigned parent community cannot be the same as child.") ) except PIDDoesNotExistError: - raise ValidationError("Assigned parent community does not exist.") + raise ValidationError(_("Assigned parent community does not exist.")) return parent def create(self, identity, data=None, record=None, **kwargs): diff --git a/invenio_communities/communities/services/service.py b/invenio_communities/communities/services/service.py index e653125ec..c64c9c1dc 100644 --- a/invenio_communities/communities/services/service.py +++ b/invenio_communities/communities/services/service.py @@ -5,6 +5,7 @@ # Copyright (C) 2021-2022 Northwestern University. # Copyright (C) 2022 Graz University of Technology. # Copyright (C) 2024 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. @@ -13,6 +14,7 @@ from flask import current_app from invenio_cache.decorators import cached_with_expiration +from invenio_i18n import lazy_gettext as _ from invenio_records_resources.proxies import current_service_registry from invenio_records_resources.services.base import LinksTemplate from invenio_records_resources.services.records import ( @@ -203,7 +205,7 @@ def rename( if "slug" not in data: raise ValidationError( - "Missing data for required field.", + _("Missing data for required field."), field_name="slug", ) diff --git a/invenio_communities/members/resources/config.py b/invenio_communities/members/resources/config.py index 3adf88fb3..e3e845f60 100644 --- a/invenio_communities/members/resources/config.py +++ b/invenio_communities/members/resources/config.py @@ -4,6 +4,7 @@ # Copyright (C) 2022-2024 Northwestern University. # Copyright (C) 2022 CERN. # Copyright (C) 2023 TU Wien. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio-Communities is free software; you can redistribute it and/or modify # it under the terms of the MIT License; see LICENSE file for more details. @@ -40,13 +41,13 @@ class MemberResourceConfig(RecordResourceConfig): InvalidMemberError: create_error_handler( HTTPJSONException( code=400, - description="Invalid member specified.", + description=_("Invalid member specified."), ) ), AlreadyMemberError: create_error_handler( HTTPJSONException( code=400, - description="A member was already added or invited.", + description=_("A member was already added or invited."), ) ), CommunityDeletedError: create_error_handler( diff --git a/invenio_communities/members/services/components.py b/invenio_communities/members/services/components.py index f4c133b4d..bf88325d8 100644 --- a/invenio_communities/members/services/components.py +++ b/invenio_communities/members/services/components.py @@ -2,6 +2,7 @@ # # This file is part of Invenio. # 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. @@ -10,6 +11,7 @@ from flask_principal import Identity from invenio_accounts.models import Role +from invenio_i18n import lazy_gettext as _ from invenio_records_resources.services.records.components import ServiceComponent from invenio_communities.members.records.api import MemberMixin @@ -29,7 +31,7 @@ def _member_changed(self, member, community=None): user_ids = [member.user_id] elif member.group_id: if not community: - raise TypeError("Community must be defined.") + raise TypeError(_("Community must be defined.")) on_group_membership_change(str(community.id)) else: return @@ -38,13 +40,13 @@ def _member_changed(self, member, community=None): user_ids = [member["id"]] elif member.get("type") == "group": if not community: - raise TypeError("Community must be defined.") + raise TypeError(_("Community must be defined.")) on_group_membership_change(str(community.id)) else: return else: raise TypeError( - "Member must be 'MemberMixin' or 'dict' but was {type}".format( + _("Member must be 'MemberMixin' or 'dict' but was {type}").format( type=type(member) ) ) diff --git a/invenio_communities/members/services/fields.py b/invenio_communities/members/services/fields.py index cce0180d4..951684391 100644 --- a/invenio_communities/members/services/fields.py +++ b/invenio_communities/members/services/fields.py @@ -2,6 +2,7 @@ # # Copyright (C) 2022 CERN. # Copyright (C) 2023 Graz University of Technology. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio-Communities is free software; you can redistribute it and/or modify # it under the terms of the MIT License; see LICENSE file for more details. @@ -41,4 +42,4 @@ def _serialize(self, value, attr, obj, **kwargs): elif isinstance(value, str): if value in current_roles: return value - raise RuntimeError("Not a valid role to serialize.") + raise RuntimeError(_("Not a valid role to serialize.")) diff --git a/invenio_communities/roles.py b/invenio_communities/roles.py index b719c3ceb..33e9c9896 100644 --- a/invenio_communities/roles.py +++ b/invenio_communities/roles.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2022 CERN. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio-Communities 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,6 +10,8 @@ from dataclasses import dataclass, field +from invenio_i18n import lazy_gettext as _ + @dataclass(frozen=True) class Role: @@ -58,9 +61,9 @@ def __init__(self, roles_definitions): for r in self._roles: if r.is_owner: - assert self._owner is None, "Only one role be defined as owner." + assert self._owner is None, _("Only one role be defined as owner.") self._owner = r - assert self._owner is not None, "One role must be defined as owner." + assert self._owner is not None, _("One role must be defined as owner.") def __contains__(self, key): """Determine if key is a valid role id.""" diff --git a/invenio_communities/subcommunities/services/schema.py b/invenio_communities/subcommunities/services/schema.py index 1b03c0182..8b1038924 100644 --- a/invenio_communities/subcommunities/services/schema.py +++ b/invenio_communities/subcommunities/services/schema.py @@ -1,11 +1,13 @@ # -*- coding: utf-8 -*- # # Copyright (C) 2024 CERN. +# Copyright (C) 2024 KTH Royal Institute of Technology. # # Invenio-Communities is free software; you can redistribute it and/or modify # it under the terms of the MIT License; see LICENSE file for more details. """Subcommunities service schemas.""" +from invenio_i18n import lazy_gettext as _ from marshmallow import Schema, ValidationError, fields, post_load, pre_load @@ -45,6 +47,6 @@ def validate(self, data, **kwargs): """Validate that either community_id or community is provided.""" if "community_id" not in data and "community" not in data: raise ValidationError( - "Either community_id or community should be provided." + _("Either community_id or community should be provided.") ) return data diff --git a/invenio_communities/views/communities.py b/invenio_communities/views/communities.py index 927ecc76a..72d543440 100644 --- a/invenio_communities/views/communities.py +++ b/invenio_communities/views/communities.py @@ -3,6 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2016-2024 CERN. # Copyright (C) 2023 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. @@ -28,7 +29,7 @@ VISIBILITY_FIELDS = [ { - "text": "Public", + "text": _("Public"), "value": "public", "icon": "group", "helpText": _( @@ -36,7 +37,7 @@ ), }, { - "text": "Restricted", + "text": _("Restricted"), "value": "restricted", "icon": "lock", "helpText": _("Your community is restricted to users" " with access."), @@ -45,7 +46,7 @@ MEMBERS_VISIBILITY_FIELDS = [ { - "text": "Public", + "text": _("Public"), "value": "public", "icon": "group", "helpText": _( @@ -54,7 +55,7 @@ ), }, { - "text": "Members-only", + "text": _("Members-only"), "value": "restricted", "icon": "lock", "helpText": _( @@ -66,7 +67,7 @@ RECORDS_SUBMISSION_POLICY_FIELDS = [ { - "text": "Open", + "text": _("Open"), "value": "open", "icon": "lock open", "helpText": _( @@ -75,23 +76,22 @@ ), }, { - "text": "Closed", + "text": _("Closed"), "value": "closed", "icon": "lock", "helpText": _("Only members can submit records to the community."), }, ] - REVIEW_POLICY_FIELDS = [ { - "text": "Review all submissions", + "text": _("Review all submissions"), "value": "closed", "icon": "lock", "helpText": _("All submissions to the community must be reviewed."), }, { - "text": "Allow curators, managers and owners to publish without review", + "text": _("Allow curators, managers and owners to publish without review"), "value": "open", "icon": "group", "helpText": _( @@ -99,7 +99,7 @@ ), }, { - "text": "Allow all members to publish without review", + "text": _("Allow all members to publish without review"), "value": "members", "icon": "lock open", "helpText": _( @@ -108,16 +108,15 @@ }, ] - MEMBER_POLICY_FIELDS = [ { - "text": "Open", + "text": _("Open"), "value": "open", "icon": "user plus", "helpText": _("Users can request to join your community."), }, { - "text": "Closed", + "text": _("Closed"), "value": "closed", "icon": "user times", "helpText": _(