Skip to content

Commit

Permalink
i18n: mark strings for translation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Arbid authored and Samk13 committed Feb 18, 2025
1 parent b01ec7a commit 2d4cb83
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* // This file is part of Invenio-Communities
* // Copyright (C) 2023-2024 CERN.
* // Copyright (C) 2024 KTH Royal Institute of Technology.
* //
* // Invenio-App-Rdm 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 @@ -85,7 +86,7 @@ export class RestoreConfirmation extends Component {
</Modal.Content>
<Modal.Actions>
<Button onClick={this.handleModalClose} floated="left">
Close
{i18next.t("Close")}
</Button>
<Button
size="small"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* // This file is part of Invenio-App-Rdm
* // Copyright (C) 2023-2024 CERN.
* // Copyright (C) 2024 KTH Royal Institute of Technology.
* //
* // Invenio-App-Rdm 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 @@ -129,7 +130,7 @@ export default class TombstoneForm extends Component {
this.handleVisibility(setFieldValue, true)
}
>
Public
{i18next.t("Public")}
</Button>
<Button
active={!values.is_visible}
Expand All @@ -139,7 +140,7 @@ export default class TombstoneForm extends Component {
this.handleVisibility(setFieldValue, false)
}
>
Hidden
{i18next.t("Hidden")}
</Button>
</Button.Group>
{!values.is_visible && isPublic && (
Expand Down Expand Up @@ -178,7 +179,7 @@ export default class TombstoneForm extends Component {
</Modal.Content>
<Modal.Actions>
<Button onClick={this.handleModalClose} floated="left">
Close
{i18next.t("Close")}
</Button>
<Button
size="small"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is part of InvenioRDM
// Copyright (C) 2022-2024 CERN.
// Copyright (C) 2024 KTH Royal Institute of Technology.
//
// Invenio App RDM 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 @@ -45,7 +46,7 @@ export const CommunityItemComputer = ({ result }) => {
{result.parent && (
<p className="ml-5 display-inline-block">
<Popup
content="Verified community"
content={i18next.t("Verified community")}
trigger={
<Icon size="small" color="green" name="check circle outline" />
}
Expand All @@ -61,7 +62,7 @@ export const CommunityItemComputer = ({ result }) => {
)}
{result.parent && (
<div className="sub header">
Part of{" "}
{i18next.t("Part of")}{" "}
<a href={`/communities/${result.parent.slug}`}>
{result.parent.metadata.title}
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is part of InvenioRDM
// Copyright (C) 2022-2024 CERN.
// Copyright (C) 2024 KTH Royal Institute of Technology.
//
// Invenio App RDM 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 @@ -91,7 +92,7 @@ export const CommunityItemMobile = ({ result, index }) => {
)}
{result.parent && (
<div className="pl-0 sub header">
Part of{" "}
{i18next.t("Part of")}{" "}
<a href={`/communities/${result.parent.slug}`}>
{result.parent.metadata.title}
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
// This file is part of InvenioRDM
// Copyright (C) 2024 CERN.
// Copyright (C) 2024 KTH Royal Institute of Technology.
//
// Invenio App RDM is free software; you can redistribute it and/or modify it
// under the terms of the MIT License; see LICENSE file for more details.

import React from "react";
import PropTypes from "prop-types";
import { Popup } from "semantic-ui-react";
import { i18next } from "@translations/invenio_app_rdm/i18next";

const OrganizationsList = ({ organizations }) => {
const handleClick = (e) => {
Expand Down Expand Up @@ -35,11 +43,13 @@ const OrganizationsList = ({ organizations }) => {
</span>
{organizations.length > 1 && (
<span className="ml-1">
&nbsp;and&nbsp;
&nbsp;{i18next.t("and")}&nbsp;
<Popup
trigger={
<a href="#!" onClick={handleClick}>
{`${organizations.length - 1} more organizations`}
{i18next.t("{{count}} more organizations", {
count: organizations.length - 1,
})}
</a>
}
size="small"
Expand Down
5 changes: 3 additions & 2 deletions invenio_communities/communities/schema.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 Down Expand Up @@ -333,8 +334,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
25 changes: 14 additions & 11 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,9 +161,9 @@ 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(
title=community_title
)
return _("Records belonging to the community '%(title)s'") % {
"title": str(community_title)
}

def _create_set_from_community(self, record):
community_slug = record.slug
Expand All @@ -173,9 +174,9 @@ 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(
id=record.id
)
community_set.search_pattern = _("parent.communities.ids:%(id)s") % {
"id": record.id
}

return community_set

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 @@ -204,7 +206,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
11 changes: 6 additions & 5 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,15 +40,14 @@ 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(
type=type(member)
)
_("Member must be 'MemberMixin' or 'dict' but was %(type)s")
% {"type": type(member)}
)

for user_id in user_ids:
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."))
22 changes: 10 additions & 12 deletions invenio_communities/members/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ def _invite_factory(self, identity, community, role, visible, member, message, u
# Add member entry
if member["type"] == "user":
# Create request
title = _('Invitation to join "{community}"').format(
community=community.metadata["title"],
)
description = _('You will join as "{role}".').format(role=role.title)
title = _('Invitation to join "%(community)s"') % {
"community": community.metadata["title"]
}
description = _('You will join as "%(role)s".') % {"role": role.title}

request_item = current_requests_service.create(
identity,
Expand Down Expand Up @@ -587,11 +587,9 @@ def _update(self, identity, community, member, role, visible, uow):
data = {
"payload": {
"content": _(
'You will join as "{role}" (changed from: "{previous}").'
).format(
role=role.title,
previous=member.role,
),
'You will join as "%(role)s" (changed from: "%(previous)s").'
)
% {"role": role.title, "previous": member.role},
}
}
current_events_service.create(
Expand Down Expand Up @@ -765,9 +763,9 @@ def request_membership(self, identity, community_id, data, uow=None):
)

# Create request
title = _('Request to join "{community}"').format(
community=community.metadata["title"],
)
title = _('Request to join "%(community)s"') % {
"community": community.metadata["title"]
}
request_item = current_requests_service.create(
identity,
data={
Expand Down
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
Loading

0 comments on commit 2d4cb83

Please sign in to comment.