Skip to content

Commit

Permalink
i18n: mark strings for translation
Browse files Browse the repository at this point in the history
Mark missing strings for:
* /admin.py
* /assets/semantic-ui/js/invenio_administration/src/actions/DeleteModal.js
* /assets/semantic-ui/js/invenio_administration/src/formik/ActionForm.js
* /assets/semantic-ui/js/invenio_administration/src/formik/AdminForm.js
* /assets/semantic-ui/js/invenio_administration/src/search/SearchEmptyResults.js
* /marshmallow_utils.py
* /menu/menu.py
* /views/base.py
* /views/dashboard.py
  • Loading branch information
Samk13 committed Feb 18, 2025
1 parent 80f3922 commit 7ec8c85
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 19 deletions.
4 changes: 3 additions & 1 deletion invenio_administration/admin.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) 2022-2024 CERN.
# Copyright (C) 2023-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 @@ -11,6 +12,7 @@

from flask import Blueprint
from flask_menu import current_menu
from invenio_i18n import lazy_gettext as _
from werkzeug.utils import import_string

from invenio_administration.menu import AdminMenu
Expand Down Expand Up @@ -50,7 +52,7 @@ def __init__(
self.blueprint = None

if name is None:
name = "Administration"
name = _("Administration")
self.name = name

self.dashboard_view_class = self.load_admin_dashboard(app)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// This file is part of InvenioAdministration
// Copyright (C) 2022 CERN.
// Copyright (C) 2024 KTH Royal Institute of Technology.
//
// Invenio RDM Records 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,14 +41,14 @@ class DeleteModal extends Component {
await InvenioAdministrationActionsApi.deleteResource(apiEndpoint);
toggleModal(false);
addNotification({
title: "Success",
content: "Resource was successfully deleted.",
title: i18next.t("Success"),
content: i18next.t("Resource was successfully deleted."),
type: "success",
});
successCallback();
} catch (e) {
this.setState({
error: { header: "Action error", content: e.message, id: e.code },
error: { header: i18next.t("Action error"), content: e.message, id: e.code },
});
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// This file is part of InvenioAdministration
// Copyright (C) 2022 CERN.
// Copyright (C) 2024 KTH Royal Institute of Technology.
//
// Invenio RDM Records 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, { Component } from "react";
import PropTypes from "prop-types";
import { Form, Formik } from "formik";
Expand Down Expand Up @@ -121,7 +128,7 @@ class ActionForm extends Component {
}

this.setState({
error: { header: "Action error", content: errorMessage, id: e.code },
error: { header: i18next.t("Action error"), content: errorMessage, id: e.code },
});
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
// This file is part of InvenioAdministration
// Copyright (C) 2022 CERN.
// Copyright (C) 2024 KTH Royal Institute of Technology.
//
// Invenio RDM Records 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, { Component } from "react";
import PropTypes from "prop-types";
import { Form, Formik } from "formik";
Expand Down Expand Up @@ -58,7 +65,7 @@ export class AdminForm extends Component {
}
} catch (e) {
console.error(`Error parsing JSON for field ${key}:`, e);
actions.setFieldError(key, "Invalid JSON format");
actions.setFieldError(key, i18next.t("Invalid JSON format"));
throw e;
}
}
Expand All @@ -81,8 +88,8 @@ export class AdminForm extends Component {
actions.setSubmitting(false);
actions.resetForm({ values: { ...values } });
addNotification({
title: "Success",
content: "Your changes were successfully submitted",
title: i18next.t("Success"),
content: i18next.t("Your changes were successfully submitted"),
type: "success",
});
successCallback(response.data);
Expand All @@ -100,7 +107,7 @@ export class AdminForm extends Component {
}

this.setState({
error: { header: "Form error", content: errorMessage, id: e.code },
error: { header: i18next.t("Form error"), content: errorMessage, id: e.code },
});
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* This file is part of Invenio.
* Copyright (C) 2022 CERN.
* 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 @@ -33,7 +34,11 @@ class SearchEmptyResults extends Component {
{isEmptyPage && i18next.t("There is no resources in this category.")}
{isEmptyPageAfterSearch && i18next.t("No matching resources found.")}
</Header>
{queryString && <em>Current search "{queryString}"</em>}
{queryString && (
<em>
{i18next.t("Current search")} "{queryString}"
</em>
)}
<br />
{isEmptyPageAfterSearch && (
<Button primary onClick={() => resetQuery()}>
Expand Down
13 changes: 10 additions & 3 deletions invenio_administration/marshmallow_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
#
# This file is part of Invenio.
# Copyright (C) 2022-2024 CERN.
# Copyright (C) 2023 KTH Royal Institute of Technology.
# Copyright (C) 2023-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.

"""Invenio administration marshmallow utils module."""
import marshmallow
from invenio_i18n import lazy_gettext as _
from marshmallow import fields
from marshmallow_utils import fields as invenio_fields
from marshmallow_utils.fields import EDTFDateString, EDTFDateTimeString
Expand Down Expand Up @@ -64,7 +65,7 @@ def find_type_in_mapping(field_type, custom_mapping):
return custom_mapping[current_type]
current_type = current_type.__base__

raise KeyError(f"Unrecognized field type: {field_type}")
raise KeyError(_("Unrecognized field type: {field_type}", field_type=field_type))


def jsonify_schema(schema):
Expand Down Expand Up @@ -159,6 +160,12 @@ def jsonify_schema(schema):
}
)
except KeyError:
raise Exception(f"Unrecognised schema field {field}: {field_type_name}")
raise Exception(
_(
"Unrecognised schema field {field}: {field_type_name}",
field=field,
field_type_name=field_type_name,
)
)

return schema_dict
3 changes: 2 additions & 1 deletion invenio_administration/menu/menu.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) 2022-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 @@ -90,7 +91,7 @@ def register_admin_entry(self, current_menu, endpoint):
def add_menu_item(self, item, index=None):
"""Add menu item."""
if not isinstance(item, MenuItem):
return TypeError("Item should be MenuItem instance.")
return TypeError(_("Item should be MenuItem instance."))

if index:
self._menu_items[index] = item
Expand Down
8 changes: 5 additions & 3 deletions invenio_administration/views/base.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) 2022-2024 CERN.
# 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 @@ -12,6 +13,7 @@

from flask import current_app, render_template, url_for
from flask.views import MethodView
from invenio_i18n import lazy_gettext as _
from invenio_search_ui.searchconfig import search_app_config

from invenio_administration.errors import (
Expand Down Expand Up @@ -256,7 +258,7 @@ class AdminResourceDetailView(AdminResourceBaseView):
item_field_exclude_list = None
item_field_list = None
template = "invenio_administration/details.html"
title = "Resource details"
title = _("Resource details")

def get_context(self, pid_value=None):
"""Create details view context."""
Expand Down Expand Up @@ -318,14 +320,14 @@ class AdminResourceEditView(AdminFormView):
"""Admin resource edit view."""

template = "invenio_administration/edit.html"
title = "Edit resource"
title = _("Edit resource")


class AdminResourceCreateView(AdminFormView):
"""Admin resource edit view."""

template = "invenio_administration/create.html"
title = "Create resource"
title = _("Create resource")


class AdminResourceListView(AdminResourceBaseView):
Expand Down
7 changes: 5 additions & 2 deletions invenio_administration/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
#
# This file is part of Invenio.
# Copyright (C) 2022 CERN.
# 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.

"""Invenio Administration dashboard view."""

from invenio_i18n import lazy_gettext as _

from invenio_administration.views.base import AdminView


Expand All @@ -18,5 +21,5 @@ class AdminDashboardView(AdminView):
name = "dashboard"
url = "/"
icon = "home"
title = "Dashboard"
menu_label = "Dashboard"
title = _("Dashboard")
menu_label = _("Dashboard")

0 comments on commit 7ec8c85

Please sign in to comment.