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: Fixing mark for translation. #416

Merged
merged 2 commits into from
Jun 9, 2022
Merged
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
4 changes: 3 additions & 1 deletion invenio_accounts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from datetime import timedelta

from flask_babelex import lazy_gettext as _

from .profiles import UserPreferencesSchema, UserProfileSchema
from .views import login

Expand Down Expand Up @@ -317,7 +319,7 @@
to reflect the changes.
"""

ACCOUNTS_USERNAME_RULES_TEXT = (
ACCOUNTS_USERNAME_RULES_TEXT = _(
"Username must start with a letter, be at least three characters long and"
" only contain alphanumeric characters, dashes and underscores."
)
Expand Down
2 changes: 1 addition & 1 deletion invenio_accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,5 +215,5 @@ def validate_username(username):
if not re.fullmatch(username_regex, username):
# if validation fails, we raise a ValueError with the configured
# text explaining the validation rules.
message = _(current_app.config["ACCOUNTS_USERNAME_RULES_TEXT"])
message = current_app.config["ACCOUNTS_USERNAME_RULES_TEXT"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACCOUNTS_USERNAME_RULES_TEXT is "double translated" in this way, I would probably only leave one of the two translation function calls, what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACCOUNTS_USERNAME_RULES_TEXT is an argument for current_app.config.
Currently the string ACCOUNTS_USERNAME_RULES_TEXT is marked for translation, meaning that we change this string and therefore the argument for current_app.config - not the message that is returned.

What we need to do is to translate the string that is returned as message instead. This is part of config.py and there we marked the respective string for translation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

raise ValueError(message)