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

more localization for two-factor #885

Merged
merged 6 commits into from
Dec 14, 2023

Conversation

gissimo
Copy link
Contributor

@gissimo gissimo commented Nov 27, 2023

I have added more localization strings in template two_factor_setup.html, and updated accordingly ES and IT translations.

Copy link

codecov bot commented Nov 27, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1c8062d) 98.33% compared to head (a22bb98) 98.33%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #885   +/-   ##
=======================================
  Coverage   98.33%   98.33%           
=======================================
  Files          34       34           
  Lines        4452     4453    +1     
=======================================
+ Hits         4378     4379    +1     
  Misses         74       74           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jwag956
Copy link
Collaborator

jwag956 commented Dec 4, 2023

Thanks - and sorry for taking a while to respond. I'd like to try to get the translations for 'primary_method' up into the form/response - rather than in the template itself - we have those strings already localized - just not a reverse look up. And there are 2 places these exist - two-factor and unified signin.
If you have time/inclination to do that - please do - otherwise - let me know and i will work on that - and let you then just add appropriate translations.

@gissimo
Copy link
Contributor Author

gissimo commented Dec 5, 2023

Hi! Thanks for feedback. I see your point. I've moved localization to views.py and created there a dictionary (like the one in forms.py) because what is shown now for primary method is a code and not really a string. Also, already existing localization strings are similar ones but not exact ones, so they need to be created anew. How do you feel about it?

Copy link
Collaborator

@jwag956 jwag956 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this - a couple small comments.

"email": _("Email"),
"mail": _("Email"),
"sms": _("SMS"),
None: _("None"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you want "None" here - not pythons None!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getattr(user, "tf_primary_method", None) in views.py#L884 can return indeed a python None, according to what's stored in user attribute. OK to have both str and None as dictionary keys?

@@ -126,6 +127,15 @@
webauthn_verify_response,
)

_tf_methods = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to see this in forms.py - that's where all the other labels are - and reference that from views. This should also make it easier to re-use in unified_signin.py which has a very similar localization issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, done!

Copy link
Collaborator

@jwag956 jwag956 left a comment

Choose a reason for hiding this comment

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

Thanks for the changes.
I think there are a few more places this same translation is needed.
In views::two_factor_token_validation - both render_template set 'chosen_method' - those I think should use the new translation table.

Same in views::two_factor_rescue:render_template

Also - in two_factor_setup - higher up in the code there is a render_template that sets chosen_method for the two_factor_verify_form - this also I think should be translated.

@gissimo
Copy link
Contributor Author

gissimo commented Dec 11, 2023

Hi!
I have added translation for chosen_method when it is used as string. However, sometimes it is then used as key inside the template. In these cases, I have left it as it is. To avoid confusion, I have added suffix _xlated for when it is a string and translated.
What do you think?

Copy link
Collaborator

@jwag956 jwag956 left a comment

Choose a reason for hiding this comment

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

Thanks for sticking with this. This is a great improvement.
See comments about maintaining backwards compatibility for templaes.

@@ -4,7 +4,7 @@
On GET:
choices: Value of SECURITY_TWO_FACTOR_ENABLED_METHODS (with possible addition of 'delete'
two_factor_required: Value of SECURITY_TWO_FACTOR_REQUIRED
primary_method: if a two-factor method has already been set up.
primary_method_xlated: if a two-factor method has already been set up.
Copy link
Collaborator

Choose a reason for hiding this comment

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

While I agree this is confusing - making this change now will break backward compatibility for applications with their own templates. From what I can see - there are no forms where the same value (primary_method) is used both as a key and as an informational piece of info (in other words - from your changes - we never have BOTH primary_method AND primary_method_xlated. So - lets favor keeping things compatible...

@@ -4,7 +4,7 @@
{% block content %}
{% include "security/_messages.html" %}
<h1>{{ _fsdomain("Two-factor Authentication") }}</h1>
<h2>{{ _fsdomain("Please enter your authentication code generated via: %(method)s", method=chosen_method) }}</h2>
<h2>{{ _fsdomain("Please enter your authentication code generated via: %(method)s", method=chosen_method_xlated) }}</h2>
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here - lets keep things compatible.

flask_security/views.py Show resolved Hide resolved
@@ -880,7 +881,9 @@ def two_factor_setup():
two_factor_verify_code_form=code_form,
choices=choices,
chosen_method=form.setup.data,
primary_method=getattr(user, "tf_primary_method", "None"),
primary_method_xlated=_tf_methods_xlate[
Copy link
Collaborator

Choose a reason for hiding this comment

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

to keep compatibility - lets change all these back to what they were (without the _xlated)

@gissimo
Copy link
Contributor Author

gissimo commented Dec 13, 2023

Hi, all change requests applied! Let me know if I can be of any help anymore.

@jwag956
Copy link
Collaborator

jwag956 commented Dec 14, 2023

Thanks!

@jwag956 jwag956 merged commit 3018dde into pallets-eco:master Dec 14, 2023
17 checks passed
@gissimo gissimo deleted the more-localization-for-two-factor branch December 20, 2023 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants