-
Notifications
You must be signed in to change notification settings - Fork 155
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
more localization for two-factor #885
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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. |
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? |
There was a problem hiding this 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.
flask_security/views.py
Outdated
"email": _("Email"), | ||
"mail": _("Email"), | ||
"sms": _("SMS"), | ||
None: _("None"), |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
flask_security/views.py
Outdated
@@ -126,6 +127,15 @@ | |||
webauthn_verify_response, | |||
) | |||
|
|||
_tf_methods = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing, done!
There was a problem hiding this 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.
Hi! |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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
Outdated
@@ -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[ |
There was a problem hiding this comment.
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)
Hi, all change requests applied! Let me know if I can be of any help anymore. |
Thanks! |
I have added more localization strings in template two_factor_setup.html, and updated accordingly ES and IT translations.