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 translations for end user msgs #1240

Open
wants to merge 4 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
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
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/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
SearchOptionsMixin,
)
from invenio_records_resources.services.files.links import FileLink
from invenio_records_resources.services.records.config import RecordServiceConfig
from invenio_records_resources.services.records.config import (
RecordServiceConfig,
)
from invenio_records_resources.services.records.config import (
SearchOptions as SearchOptionsBase,
)
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
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
Loading
Loading