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

Run string formatting after gettext() call #6368

Merged
merged 1 commit into from Mar 29, 2022
Merged

Conversation

legoktm
Copy link
Member

@legoktm legoktm commented Mar 29, 2022

Status

Ready for review

Description of Changes

Don't interpolate parameters before looking up the string in gettext,
otherwise it won't find anything and fallback to English.

Fixes #6367.

Testing

  • Rebase onto @cfm's i18n branch (which might not exist yet), enable minimum length, change language to German, verify no raw {} appear in the error message when inputting too short of a message, and the correct character count is shown.

Deployment

Any special considerations for deployment? No.

Checklist

  • Linting (make lint) and tests (make test) pass in the development container
  • These changes do not require documentation

Don't interpolate parameters before looking up the string in gettext,
otherwise it won't find anything and fallback to English.

Fixes #6367.
@legoktm legoktm requested a review from a team as a code owner March 29, 2022 20:47
@zenmonkeykstop zenmonkeykstop self-assigned this Mar 29, 2022
@codecov-commenter
Copy link

codecov-commenter commented Mar 29, 2022

Codecov Report

Merging #6368 (c33cbe4) into develop (1cc675f) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop    #6368   +/-   ##
========================================
  Coverage    83.98%   83.98%           
========================================
  Files           61       61           
  Lines         4301     4301           
  Branches       522      522           
========================================
  Hits          3612     3612           
  Misses         565      565           
  Partials       124      124           
Impacted Files Coverage Δ
securedrop/source_app/main.py 93.20% <ø> (ø)

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Copy link
Contributor

@zenmonkeykstop zenmonkeykstop left a comment

Choose a reason for hiding this comment

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

LGTM based on visual review and testing in make dev.

@@ -46,11 +46,11 @@ <h2 id="submit-heading" class="headline">{{ gettext('Submit Messages') }}</h2>
{{ form.msg(class="fill-parent") }}
{% if allow_document_uploads %}
{% if min_len > 0 %}
<p class="center" id="min-msg-length">{{ gettext('If you are only sending a message, it must be at least {} characters long.'.format(min_len)) }}</p>
<p class="center" id="min-msg-length">{{ gettext('If you are only sending a message, it must be at least {} characters long.').format(min_len) }}</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Testing: this case did not work correctly, but that's due to this string not being collected for translation, the code change is valid.

@@ -204,7 +204,7 @@ def submit(logged_in_source: SourceUser) -> werkzeug.Response:
min_len = InstanceConfig.get_default().initial_message_min_len
if (min_len > 0) and (msg and not fh) and (len(msg) < min_len):
flash(gettext(
"Your first message must be at least {} characters long.".format(min_len)),
"Your first message must be at least {} characters long.").format(min_len),
Copy link
Contributor

Choose a reason for hiding this comment

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

testing - confirmed that this case works correctly when rebased onto the i18n-merge branch.

{% endif %}
{% else %}
{% if min_len > 0 %}
<p class="center" id="min-msg-length">{{ gettext('Your first message must be at least {} characters long.'.format(min_len)) }}</p>
<p class="center" id="min-msg-length">{{ gettext('Your first message must be at least {} characters long.').format(min_len) }}</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

Testing: this case works correctly (with min-length set and document uploads disabled).

@zenmonkeykstop zenmonkeykstop merged commit 0598f5b into develop Mar 29, 2022
SecureDrop Team Board automation moved this from Ready for Review to Done Mar 29, 2022
@legoktm legoktm deleted the gettext-format branch March 30, 2022 16:58
@zenmonkeykstop zenmonkeykstop mentioned this pull request May 10, 2022
35 tasks
cfm added a commit that referenced this pull request May 23, 2022
lsd-cat pushed a commit to lsd-cat/securedrop-public that referenced this pull request Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

anonymous string-formatting fields break translation
3 participants