Skip to content

Commit

Permalink
i18n: mark translations for end user msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Arbid committed Oct 19, 2024
1 parent e6c3901 commit 71e7411
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 32 deletions.
4 changes: 2 additions & 2 deletions invenio_communities/communities/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
17 changes: 10 additions & 7 deletions invenio_communities/communities/services/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
)

Expand All @@ -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
)

Expand Down Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion invenio_communities/communities/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 (
Expand Down Expand Up @@ -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",
)

Expand Down
5 changes: 3 additions & 2 deletions invenio_communities/members/resources/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 5 additions & 3 deletions invenio_communities/members/services/components.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) 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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
)
)
Expand Down
3 changes: 2 additions & 1 deletion invenio_communities/members/services/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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."))
7 changes: 5 additions & 2 deletions invenio_communities/roles.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -9,6 +10,8 @@

from dataclasses import dataclass, field

from invenio_i18n import lazy_gettext as _


@dataclass(frozen=True)
class Role:
Expand Down Expand Up @@ -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."""
Expand Down
4 changes: 3 additions & 1 deletion invenio_communities/subcommunities/services/schema.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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
25 changes: 12 additions & 13 deletions invenio_communities/views/communities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -28,15 +29,15 @@

VISIBILITY_FIELDS = [
{
"text": "Public",
"text": _("Public"),
"value": "public",
"icon": "group",
"helpText": _(
"Your community is publicly accessible" " and shows up in search results."
),
},
{
"text": "Restricted",
"text": _("Restricted"),
"value": "restricted",
"icon": "lock",
"helpText": _("Your community is restricted to users" " with access."),
Expand All @@ -45,7 +46,7 @@

MEMBERS_VISIBILITY_FIELDS = [
{
"text": "Public",
"text": _("Public"),
"value": "public",
"icon": "group",
"helpText": _(
Expand All @@ -54,7 +55,7 @@
),
},
{
"text": "Members-only",
"text": _("Members-only"),
"value": "restricted",
"icon": "lock",
"helpText": _(
Expand All @@ -66,7 +67,7 @@

RECORDS_SUBMISSION_POLICY_FIELDS = [
{
"text": "Open",
"text": _("Open"),
"value": "open",
"icon": "lock open",
"helpText": _(
Expand All @@ -75,31 +76,30 @@
),
},
{
"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": _(
"Submissions to the community by default requires review, but curators, managers and owners can publish directly without review."
),
},
{
"text": "Allow all members to publish without review",
"text": _("Allow all members to publish without review"),
"value": "members",
"icon": "lock open",
"helpText": _(
Expand All @@ -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": _(
Expand Down

0 comments on commit 71e7411

Please sign in to comment.