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

Add simplified Chinese as a supported language #5697

Merged
merged 3 commits into from
Jan 12, 2021
Merged

Conversation

rmol
Copy link
Contributor

@rmol rmol commented Jan 11, 2021

Status

Ready for review

Description of Changes

Fixes #5069.

This ended up requiring quite a bit more than just updating the supported languages in securedrop/i18n_tool.py and updating the translations from Weblate.

The way we were naming locales in the selection dropdown, using only part of the language name, wasn't sufficient to distinguish simplified and traditional Chinese. It was also off for Norwegian, in that we were just calling it "Norsk", which isn't the complete language name, indicating which written standard we use (Bokmål). So I've changed it to use the complete language name, and include further distinguishing information as necessary when we have more than one translation for a language.

We were also constructing the mapping of locale identifiers to display names every request, but always using the locale endonyms for the display names, instead of showing display names in the visitor's language, so it didn't need to be done per request. I moved the creation of the locale name map to the app setup.

Our negotiation of locales using the request's accepted languages was also not working for Chinese, because we store the Chinese translations by language and script, not region, so if a browser indicated acceptable Chinese locales containing regions, they wouldn't be matched and the visitor's first contact would be in English.

While cleaning up the locale selector presentation, I consolidated some of the things we were tacking onto the Flask g object into a container class, i18n.RequestLocaleInfo.

The source metadata API endpoint could duplicate the default locale in its list of supported languages. That's been fixed.

Testing

If testing with the dev server, move or remove any existing securedrop/config.py.

Simplified Chinese is a functional option in the locale selector

  • 中文 (简体) is an option in the locale selector, and choosing it results in pages rendered in simplified Chinese. Confirm that the content is different from traditional Chinese.

Browser locale negotiation

  • Clearing the session cookie and visiting the site with the browser's preferred language set to simplified Chinese (Firefox calls it "Chinese (China)") results in the site being rendered in simplified Chinese by default, not English.
  • Clearing the session cookie and visiting the site with the browser's preferred language set to traditional Chinese (Firefox calls it "Chinese (Taiwan)") results in the site being rendered in traditional Chinese by default, not English.
  • Clearing the session cookie and visiting the site with the browser's preferred language set to something other than English or Chinese also results in pages rendered in that language.

Other locale functionality

  • Ensure that manually selecting any locale changes the UI persistently -- if you navigate around the source and journalist interfaces, every page should be in your chosen locale.
  • As a source, upload a file larger than a megabyte. When viewing the source's collection in the JI, the file size decimal separator should be a period for Arabic, Chinese, English, and Hindi, and a comma for others.
  • Reply to the source, then check the reply in the SI. The timestamp should be localized properly -- be sure to hover over it to check the full timestamp.
  • After changing the locale, the <html> element of any page has both dir and lang attribute set correctly. For Arabic, dir is set to rtl. The lang attribute should be a hyphenated locale identifier, per RFC5646/BCP47, where our locale includes a region or script (e.g. de_DE, zh_Hant).

Source metadata API

  • Check http://localhost:8080/metadata and ensure that supported_languages matches config.SUPPORTED_LOCALES, with each identifier only appearing once (English used to be repeated). Ensure that zh_Hans (simplified Chinese) is present.

Deployment

These changes:

  • modify securedrop/sdconfig.py to produce a cleaner SUPPORTED_LOCALES setting.
  • modify app and request setup in both journalist and source interfaces.

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

Choose one of the following:

  • I have opened a PR in the docs repo for these changes, or will do so later
  • I would appreciate help with the documentation
  • These changes do not require documentation

@emkll emkll added this to Ready for Review in SecureDrop Team Board Jan 11, 2021
The way we were naming locales in the selection dropdown, using only
part of the language name, wasn't sufficient to distinguish simplified
and traditional Chinese. It was also off for Norwegian, in that we
were just calling it "Norsk", which isn't the complete language name,
indicating which written standard we use (Bokmål). So I've changed it
to use the complete language name, and include further distinguishing
information as necessary when we have more than one translation for a
language.

We were also constructing the mapping of locale identifiers to display
names every request, but always using the locale endonyms for the
display names, instead of showing display names in the visitor's
language, so it didn't need to be done per request. I moved the
creation of the locale name map to the app setup.

Our negotiation of locales using the request's accepted languages was
also not working for Chinese, because we store the Chinese
translations by language and script, not region, so if a browser
indicated acceptable Chinese locales containing regions, they wouldn't
be matched and the visitor's first contact would be in English.

While cleaning up the locale selector presentation, I consolidated
some of the things we were tacking onto the Flask g object into a
container class, i18n.RequestLocaleInfo.

The source metadata API endpoint could duplicate the default locale in
its list of supported languages. That's been fixed.
Copy link
Contributor

@kushaldas kushaldas left a comment

Choose a reason for hiding this comment

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

Took a lot of time to figure out that I should delete my old config.py 👍🏽

Testing

Simplified Chinese is a functional option in the locale selector

  • 中文 (简体) is an option in the locale selector, and choosing it results in pages rendered in simplified Chinese. Confirm that the content is different from traditional Chinese.

Browser locale negotiation

  • Clearing the session cookie and visiting the site with the browser's preferred language set to simplified Chinese (Firefox calls it "Chinese (China)") results in the site being rendered in simplified Chinese by default, not English.
  • Clearing the session cookie and visiting the site with the browser's preferred language set to traditional Chinese (Firefox calls it "Chinese (Taiwan)") results in the site being rendered in traditional Chinese by default, not English.
  • Clearing the session cookie and visiting the site with the browser's preferred language set to something other than English or Chinese also results in pages rendered in that language.

Other locale functionality

  • Ensure that manually selecting any locale changes the UI persistently -- if you navigate around the source and journalist interfaces, every page should be in your chosen locale.
  • [❌] As a source, upload a file larger than a megabyte. When viewing the source's collection in the JI, the file size thousands separator is adjusted correctly (commas for Arabic, Chinese, English, and Hindi; periods for others). -- This came as . for me in Arabic or Hindi
  • Reply to the source, then check the reply in the SI. The timestamp should be localized properly -- be sure to hover over it to check the full timestamp.
  • After changing the locale, the <html> element of any page has both dir and lang attribute set correctly. For Arabic, dir is set to rtl. The lang attribute should be a hyphenated locale identifier, per RFC5646/BCP47, where our locale includes a region or script (e.g. de_DE, zh_Hant).

Source metadata API

  • Check http://localhost:8080/metadata and ensure that supported_languages matches config.SUPPORTED_LOCALES, with each identifier only appearing once (English used to be repeated). Ensure that zh_Hans (simplified Chinese) is present.

@rmol
Copy link
Contributor Author

rmol commented Jan 12, 2021

When viewing the source's collection in the JI, the file size thousands separator is adjusted correctly (commas for Arabic, Chinese, English, and Hindi; periods for others).

"Impressive. Every word in that sentence was wrong." Sorry for the goose chase @kushaldas. There shouldn't ever be a thousands separator in the file size. There, the decimal separator should be adjusted correctly, and it should be a comma except for Arabic, Chinese, English and Hindi. I'll correct the test plan.

Copy link
Contributor

@conorsch conorsch left a comment

Choose a reason for hiding this comment

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

Looks good. I noticed one deviation from the test plan, but it appears related to me being a stickler on interpreting a test plan, and not actually surprising behavior that needs to be changed in the app.

Simplified Chinese is a functional option in the locale selector

  • 中文 (简体) is an option in the locale selector, and choosing it results in pages rendered in simplified Chinese. Confirm that the content is different from traditional Chinese.

Browser locale negotiation

  • Clearing the session cookie and visiting the site with the browser's preferred language set to simplified Chinese (Firefox calls it "Chinese (China)") results in the site being rendered in simplified Chinese by default, not English.
  • Clearing the session cookie and visiting the site with the browser's preferred language set to traditional Chinese (Firefox calls it "Chinese (Taiwan)") results in the site being rendered in traditional Chinese by default, not English.
  • Clearing the session cookie and visiting the site with the browser's preferred language set to something other than English or Chinese also results in pages rendered in that language.

Other locale functionality

  • 🟠 Ensure that manually selecting any locale changes the UI persistently -- if you navigate around the source and journalist interfaces, every page should be in your chosen locale.
    • See screenshot below. I set the browser locale to Chinese, but used the in-app language selector to set German. On the Source Submit screen, the browser widget buttons were still Chinese, but the rest of the app test was in German. That's unsurprising to me and I believe acceptable.
  • As a source, upload a file larger than a megabyte. When viewing the source's collection in the JI, the file size decimal separator should be a period for Arabic, Chinese, English, and Hindi, and a comma for others.
  • Reply to the source, then check the reply in the SI. The timestamp should be localized properly -- be sure to hover over it to check the full timestamp.
  • After changing the locale, the <html> element of any page has both dir and lang attribute set correctly. For Arabic, dir is set to rtl. The lang attribute should be a hyphenated locale identifier, per RFC5646/BCP47, where our locale includes a region or script (e.g. de_DE, zh_Hant).

Source metadata API

  • Check http://localhost:8080/metadata and ensure that supported_languages matches config.SUPPORTED_LOCALES, with each identifier only appearing once (English used to be repeated). Ensure that zh_Hans (simplified Chinese) is present.

Screenshot as promised:

mixed-languages

@conorsch conorsch dismissed kushaldas’s stale review January 12, 2021 18:48

Test plan has been updated based on feedback

@conorsch
Copy link
Contributor

I've dismissed @kushaldas's review since the test plan has been updated. @rmol please see screenshot above, otherwise fine to merge from my end!

@rmol
Copy link
Contributor Author

rmol commented Jan 12, 2021

Yeah, we don't have any control over the native widget text, as far as I know; they're rendered like the rest of the browser UI. There are JS/CSS hacks around, but the standard behavior seems the most intuitive and least surprising.

@sssoleileraaa sssoleileraaa merged commit 89bb69d into develop Jan 12, 2021
SecureDrop Team Board automation moved this from Ready for Review to Done Jan 12, 2021
@conorsch conorsch mentioned this pull request Jan 15, 2021
22 tasks
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.

Add simplified Chinese (zh_Hans) to the list of supported languages
4 participants