diff --git a/invenio_accounts/admin.py b/invenio_accounts/admin.py index cf14baa1..16aba888 100644 --- a/invenio_accounts/admin.py +++ b/invenio_accounts/admin.py @@ -2,6 +2,7 @@ # # This file is part of Invenio. # Copyright (C) 2015-2018 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. @@ -45,14 +46,14 @@ class UserView(ModelView): form_columns = ("email", "password", "active", "roles", "notification") form_args = dict( - email=dict(label="Email", validators=[DataRequired()]), + email=dict(label=lazy_gettext("Email"), validators=[DataRequired()]), password=dict(default=lambda: pwd.genword(length=12)), ) form_extra_fields = { "notification": BooleanField( - "Send User Notification", - description="Send the new user an email about their account.", + lazy_gettext("Send User Notification"), + description=lazy_gettext("Send the new user an email about their account."), ) } @@ -74,8 +75,8 @@ def after_model_change(self, form, User, is_created): @action( "inactivate", - _("Inactivate"), - _("Are you sure you want to inactivate selected users?"), + lazy_gettext("Inactivate"), + lazy_gettext("Are you sure you want to inactivate selected users?"), ) @commit def action_inactivate(self, ids): @@ -99,8 +100,8 @@ def action_inactivate(self, ids): @action( "activate", - _("Activate"), - _("Are you sure you want to activate selected users?"), + lazy_gettext("Activate"), + lazy_gettext("Are you sure you want to activate selected users?"), ) @commit def action_activate(self, ids): @@ -159,9 +160,9 @@ class SessionActivityView(ModelView): list_all = ("user.id", "user.email", "sid_s", "created") column_labels = { - "user.id": "User ID", - "user.email": "Email", - "sid_s": "Session ID", + "user.id": lazy_gettext("User ID"), + "user.email": lazy_gettext("Email"), + "sid_s": lazy_gettext("Session ID"), } column_list = list_all column_filters = list_all @@ -174,7 +175,7 @@ class SessionActivityView(ModelView): def delete_model(self, model): """Delete a specific session.""" if SessionActivity.is_current(sid_s=model.sid_s): - flash("You could not remove your current session", "error") + flash(_("You could not remove your current session"), "error") return delete_session(sid_s=model.sid_s) db.session.commit() @@ -188,7 +189,7 @@ def action_delete(self, ids): """Delete selected sessions.""" is_current = any(SessionActivity.is_current(sid_s=id_) for id_ in ids) if is_current: - flash("You could not remove your current session", "error") + flash(_("You could not remove your current session"), "error") return for id_ in ids: delete_session(sid_s=id_) @@ -218,34 +219,34 @@ class UserIdentityView(ModelView): ) column_labels = { - "user.email": _("Email"), - "id_user": _("User ID"), + "user.email": lazy_gettext("Email"), + "id_user": lazy_gettext("User ID"), } session_adminview = { "model": SessionActivity, "modelview": SessionActivityView, - "category": _("User Management"), + "category": lazy_gettext("User Management"), } user_adminview = { "model": User, "modelview": UserView, - "category": _("User Management"), + "category": lazy_gettext("User Management"), } role_adminview = { "model": Role, "modelview": RoleView, - "category": _("User Management"), + "category": lazy_gettext("User Management"), } user_identity_adminview = { "model": UserIdentity, "modelview": UserIdentityView, - "category": _("User Management"), - "name": _("Linked account identities"), + "category": lazy_gettext("User Management"), + "name": lazy_gettext("Linked account identities"), } __all__ = ( diff --git a/invenio_accounts/config.py b/invenio_accounts/config.py index 697810fa..71181f90 100644 --- a/invenio_accounts/config.py +++ b/invenio_accounts/config.py @@ -3,7 +3,7 @@ # This file is part of Invenio. # Copyright (C) 2016-2018 CERN. # Copyright (C) 2021 TU Wien. -# Copyright (C) 2022 KTH Royal Institute of Technology +# Copyright (C) 2022-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 +13,7 @@ from datetime import timedelta from invenio_i18n import lazy_gettext as _ +from invenio_i18n import gettext as _t from .profiles import UserPreferencesSchema, UserProfileSchema from .views import login @@ -201,19 +202,19 @@ SECURITY_CHANGE_URL = "/account/settings/password/" """URL endpoint for password change.""" -SECURITY_MSG_LOCAL_LOGIN_DISABLED = ("Local login is disabled.", "error") +SECURITY_MSG_LOCAL_LOGIN_DISABLED = (_t("Local login is disabled."), "error") """The error to be displayed in REST login when local login is disabled.""" -SECURITY_MSG_REGISTRATION_DISABLED = ("Registration is disabled.", "error") +SECURITY_MSG_REGISTRATION_DISABLED = (_t("Registration is disabled."), "error") """The error to be displayed in REST registration when it is disabled.""" -SECURITY_MSG_PASSWORD_CHANGE_DISABLED = ("Password change is disabled.", "error") +SECURITY_MSG_PASSWORD_CHANGE_DISABLED = (_t("Password change is disabled."), "error") """The error to be displayed in REST password change when it is disabled.""" -SECURITY_MSG_PASSWORD_RECOVERY_DISABLED = ("Password recovery is disabled.", "error") +SECURITY_MSG_PASSWORD_RECOVERY_DISABLED = (_t("Password recovery is disabled."), "error") """The error to be displayed in REST password recovery when it is disabled.""" -SECURITY_MSG_PASSWORD_RESET_DISABLED = ("Password reset is disabled.", "error") +SECURITY_MSG_PASSWORD_RESET_DISABLED = (_t("Password reset is disabled."), "error") """The error to be displayed in REST password reset when it is disabled.""" REMEMBER_COOKIE_DURATION = timedelta(days=90) diff --git a/invenio_accounts/views/security.py b/invenio_accounts/views/security.py index f73e3dd6..4a178578 100644 --- a/invenio_accounts/views/security.py +++ b/invenio_accounts/views/security.py @@ -2,6 +2,7 @@ # # This file is part of Invenio. # Copyright (C) 2017-2018 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. @@ -12,6 +13,7 @@ from flask_login import login_required from flask_security import current_user from invenio_db import db +from invenio_i18n import gettext as _ from ..forms import RevokeForm from ..models import SessionActivity @@ -58,7 +60,7 @@ def revoke_session(): if not SessionActivity.is_current(sid_s=sid_s): # if it's the same session doesn't show the message, otherwise # the session will be still open without the database record - flash("Session {0} successfully removed.".format(sid_s), "success") + flash(_("Session {0} successfully removed.").format(sid_s), "success") else: - flash("Unable to remove the session {0}.".format(sid_s), "error") + flash(_("Unable to remove the session {0}.").format(sid_s), "error") return redirect(url_for("invenio_accounts.security"))