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

Improve pluralization of translated strings #5567

Merged
merged 4 commits into from
Oct 19, 2020
Merged

Improve pluralization of translated strings #5567

merged 4 commits into from
Oct 19, 2020

Conversation

rmol
Copy link
Contributor

@rmol rmol commented Oct 8, 2020

Status

Ready for review

Description of Changes

Switch a few strings containing numeric variables to ngettext from gettext, to ensure they can be properly translated. Use "num" more consistently as the placeholder for numeric variables in strings marked with ngettext, to make things easier for translators.

Fixes #5566.

Testing

  • git checkout -b more-plurals origin/more-plurals
  • make translate
  • Choose a test language, e.g. de_DE and edit its .po file (securedrop/translations/de_DE/LC_MESSAGES/messages.po) to find the updated source strings, remove the fuzzy markers, and correct the placeholder names.
  • In that .po file's directory, run msgfmt messages.po.
  • Run make dev.
  • Visit the journalist interface, switch to your test language, and ensure that the strings are being translated correctly:
    • Visit the admin page to add a new user.
      • Enter a HOTP secret a few characters long.
      • Enter less than three characters in the username field.
      • Enter more than 100 characters in the first and last name fields.
      • Pressing add user should result in properly-translated error messages.
    • Visit the source list and verify that the document, message, and unread counts are being properly translated. You'll need to submit a single file and document as a new source to test singular translations.
    • Delete a single source from the source list. The {num} collection deleted message should be properly translated.
    • Delete more than one source from the source list. The {num} collections deleted message should be properly translated.
    • Delete a single source submission. The Submission deleted flash message should be properly translated.
    • Delete more than one source submission. The {num} submissions deleted flash message should be properly translated.

Deployment

The updated strings will need to be translated at the next release. Until then, they'll always appear in English.

Checklist

If you made changes to the server application code:

  • Linting (make lint) and tests (make test) pass in the development container

If you made non-trivial code changes:

  • I have written a test plan and validated it for this PR

@emkll
Copy link
Contributor

emkll commented Oct 13, 2020

Thanks @rmol test plan as described is passing, however encountered an error locally prior to updating the translations. Without the translations generated, an error is thrown (likely due to the name of the variables changing) but is being caught by the API error handler in https://github.com/freedomofpress/securedrop/blob/more-plurals/securedrop/journalist_app/__init__.py#L92:

  File "/home/user/src/securedrop/securedrop/journalist_app/__init__.py", line 92, in _handle_http_exception
    handler = list(app.error_handler_spec['api'][error.code].values())[0]
AttributeError: 'KeyError' object has no attribute 'code'

Error handling here might warrant further investigation and/or we we consider strings as as part of this PR to support multiple languages in develop (prior to merging string changes). Right now, on this branch, using any other language than English on the source list of the journalist interface will result in error 500.

@rmol
Copy link
Contributor Author

rmol commented Oct 13, 2020

I've updated the translations. There should be no more errors because of the changed strings, and in the next translation period, translators should only have to update the strings newly marked with ngettext, and only in the languages with multiple plural forms.

@emkll
Copy link
Contributor

emkll commented Oct 15, 2020

(rebased on latest develop)

@emkll
Copy link
Contributor

emkll commented Oct 15, 2020

Looks like translation tests are failing after the rebase on latest develop, it is likely due to the Tor Browser update introduced in #5578

Switch a few strings containing numeric variables to ngettext from
gettext, to ensure they can be properly translated. Use "num" more
consistently as the placeholder for numeric variables in strings
marked with ngettext, to make things easier for translators.
For languages with only one plural form, I've renamed the placeholders
and removed the "fuzzy" mark from all updated translations in the .po
files. Translators should not need to do anything for these at the
next release.

For languages with multiple plural forms:

- For strings with changed placeholders that were already marked with
ngettext, I've just updated the placeholders in the translations and
removed the fuzzy marks. Translators should not need to do anything
for these.

- For strings newly marked with ngettext, I updated the placeholders
but left the translations marked fuzzy, so Weblate should show them as
needing editing, and translators will have a chance to correct the new
plural versions.
In translation-test, unlike run and run-test, REPOROOT isn't used. As
it is required a couple of times in dev-deps, ensure that it is set
and available to all the functions there, without overriding any
existing value in the environment.
@rmol
Copy link
Contributor Author

rmol commented Oct 15, 2020

I think it was actually my fix for Redis dump file version incompatibility. The translation-test script never sets REPOROOT, breaking the run-redis function and causing the Redis connection errors and subsequent Selenium timeouts. I added a commit to make sure it does get set in dev-deps before it's used, and so far so good.

@rmol
Copy link
Contributor Author

rmol commented Oct 16, 2020

Nope, after rebasing, also had problems running the newly-type-hinted i18n_tool.py under Python 2 (ahem), so updated the translation test job to use Python 3. About time. Translation tests are now passing.

Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

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

Thanks @rmol looks good to me, went through the diff and the functional test of the translations:

  • Visit the journalist interface, switch to your test language, and ensure that the strings are being translated correctly:
  • Enter a HOTP secret a few characters long.
  • Enter less than three characters in the username field.
  • Enter more than 100 characters in the first and last name fields.
  • Pressing add user should result in properly-translated error messages.
  • Visit the source list and verify that the document, message, and unread counts are being properly translated. You'll need to submit a single file and document as a new source to test singular translations.
  • Delete a single source from the source list. The {num} collection deleted message should be properly translated.
  • Delete more than one source from the source list. The {num} collections deleted message should be properly translated.
  • Delete a single source submission. The Submission deleted flash message should be properly translated.
  • Delete more than one source submission. The {num} submissions deleted flash message should be properly translated.

I've noticed that for cs, ro, ru and sk, the fuzzy attribute is preserved in the translations of the strings that were touched. was this intentional?

Copy link
Contributor

@emkll emkll left a comment

Choose a reason for hiding this comment

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

Approving based on previous review, as discussed fuzzy translation for those four languages is expected.

@emkll emkll merged commit 44a2e52 into develop Oct 19, 2020
@emkll emkll deleted the more-plurals branch October 19, 2020 16:24
@eloquence eloquence added this to the 1.7.0 milestone Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A few UI strings containing numeric variables can't be pluralized by translators
3 participants