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

Chrome's translate feature cannot reliably translate JavaScript reference page #5379

Open
3 tasks done
Hill-98 opened this issue Mar 1, 2022 · 10 comments
Open
3 tasks done
Labels
3rd-party Issues related to third-parties, such as Pocket or Google Translate ♿ a11y An MDN Web Docs accessible by everyone 🐌 idle Issues and PRs without recent activity. Flagged for maintainer follow-up. idle localization i18n & l10n p3 We don't have visibility when this will be addressed.

Comments

@Hill-98
Copy link

Hill-98 commented Mar 1, 2022

Summary

Chrome's translation feature doesn't work on the redesigned MDN's JavaScript reference page, and when I try to translate an English page to another language, the text always reverts to English in a flash.

Where did you spot the bug?

https://developer.mozilla.org/en-US/docs/Web/JavaScript

What is the problem?

Chrome translation does not work on JavaScript reference pages

What did you expect to happen?

Chrome translation works properly on JavaScript reference pages

Steps to reproduce the issue

  1. Open https://developer.mozilla.org/en-US/docs/Web/JavaScript in Chrome
  2. Use the translation feature to translate into languages other than English

Environment

Device

  • Desktop

Browser

  • Chrome: 98.0.4758.102

Operating system

  • Windows: Windows 11 22000.527

Screenshots

@github-actions github-actions bot added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Mar 1, 2022
@schalkneethling schalkneethling added the redesign issues related to the new design label Mar 1, 2022
@schalkneethling
Copy link
Contributor

I can confirm that this is correct. The translation tool fails to translate the page.

Screenshot showing Google translate failing to translate a page

@schalkneethling schalkneethling added ♿ a11y An MDN Web Docs accessible by everyone p1 We will address this soon and will provide capacity from our team for it in the next few releases. labels Mar 8, 2022
@caugner caugner added p2 We want to address this but may have other higher priority items. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. p1 We will address this soon and will provide capacity from our team for it in the next few releases. labels Mar 11, 2022
@caugner caugner self-assigned this Mar 11, 2022
@caugner caugner added the 3rd-party Issues related to third-parties, such as Pocket or Google Translate label Mar 11, 2022
@caugner
Copy link
Contributor

caugner commented Mar 14, 2022

FWIW Translation via https://translate.google.com/ works: https://developer-mozilla-org.translate.goog/en-US/docs/Web/JavaScript?_x_tr_sl=en&_x_tr_tl=de&_x_tr_hl=en&_x_tr_pto=wapp

When I try to translate with Chrome, I'm getting the following error in the JavaScript console:

Refused to load the stylesheet 'https://translate.googleapis.com/translate_static/css/translateelement.css' because it violates the following Content Security Policy directive: "style-src 'report-sample' 'self' 'unsafe-inline'". Note that 'style-src-elem' was not explicitly set, so 'style-src' is used as a fallback.

Background: https://rapidsec.com/csp-packages/google_translate

So it looks like to support Google Translate via Chrome, we will have to adjust our Content-Security-Policy here:

const scriptSrcValues = [
"'report-sample'",
"'self'",
"*.speedcurve.com",
"'sha256-q7cJjDqNO2e1L5UltvJ1LhvnYN7yJXgGO7b6h9xkL1o='", // LUX
"www.google-analytics.com/analytics.js",
"'sha256-JEt9Nmc3BP88wxuTZm9aKNu87vEgGmKW1zzy/vb1KPs='", // polyfill check
"polyfill.io/v3/polyfill.min.js",
"assets.codepen.io",
"production-assets.codepen.io",
"'sha256-CUy3BwqnmCSHS96nUyHoUsOB3r+s10eRpf5GbZdZqgk='", // inline no flicker
];
const CSP_DIRECTIVES = {
"default-src": ["'self'"],
"script-src": scriptSrcValues,
"script-src-elem": scriptSrcValues,
"style-src": ["'report-sample'", "'self'", "'unsafe-inline'"],
"object-src": ["'none'"],
"base-uri": ["'self'"],
"connect-src": [
"'self'",
"www.google-analytics.com",
"stats.g.doubleclick.net",
],
"font-src": ["'self'"],
"frame-src": [
"'self'",
"interactive-examples.mdn.mozilla.net",
"interactive-examples.prod.mdn.mozilla.net",
"interactive-examples.stage.mdn.mozilla.net",
"mdn.github.io",
"yari-demos.prod.mdn.mozit.cloud",
"mdn.mozillademos.org",
"yari-demos.stage.mdn.mozit.cloud",
"jsfiddle.net",
"www.youtube-nocookie.com",
"codepen.io",
],
"img-src": [
"'self'",
// Avatars
"*.githubusercontent.com",
"*.googleusercontent.com",
"mozillausercontent.com",
"profile.stage.mozaws.net",
"profile.accounts.firefox.com",
"lux.speedcurve.com",
"mdn.mozillademos.org",
"media.prod.mdn.mozit.cloud",
"media.stage.mdn.mozit.cloud",
"interactive-examples.mdn.mozilla.net",
"interactive-examples.prod.mdn.mozilla.net",
"interactive-examples.stage.mdn.mozilla.net",
"wikipedia.org",
"www.google-analytics.com",
"www.gstatic.com",
],
"manifest-src": ["'self'"],
"media-src": ["'self'", "archive.org", "videos.cdn.mozilla.net"],
"worker-src": ["'none'"],
};

@caugner
Copy link
Contributor

caugner commented Mar 14, 2022

Here's a screenshot of the network requests triggered by translating http://example.com/ with Chrome's translate feature:

image

So I believe we need to

  • add translate.googleapis.com to style-src
  • add translate.google.com to image-src

And I will see if I can create a PR shortly.

@caugner caugner added the has PR Issues that already have a PR label Mar 14, 2022
@caugner
Copy link
Contributor

caugner commented Mar 14, 2022

CSP was not the cause, because other articles translated without any issues.

Here are two observations I made:

  • If I remove the left sidebar or the main content from the DOM, translation works fine.
  • If I open the Chrome DevTools and reload the article, translation works fine.

This all sounds more like a Chrome bug than a MDN bug, and in fact there is a very recent issue in Chrome's bug tracker: https://bugs.chromium.org/p/chromium/issues/detail?id=1304514

@caugner caugner added p3 We don't have visibility when this will be addressed. and removed p2 We want to address this but may have other higher priority items. has PR Issues that already have a PR redesign issues related to the new design labels Mar 14, 2022
@caugner caugner changed the title Bug: Redesign for JavaScript reference page doesn't work with Chrome's translate Chrome's translate feature cannot reliably translate JavaScript reference page Mar 14, 2022
@caugner
Copy link
Contributor

caugner commented Mar 14, 2022

If I visit chrome://translate-internals/#detection-logs in Chrome, I see a 6: Translation Error, but no details:

image

According to the Detection Logs tabs, Chrome extracts the article's content properly:

Screenshot 2022-03-14 at 20 08 16

@caugner caugner removed their assignment Mar 14, 2022
@schalkneethling
Copy link
Contributor

It indeed works just fine on https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach for example. I was also able to translate the above page from English to Arabic

Screenshot of MDN forEach page in Arabic

@schalkneethling
Copy link
Contributor

@Hill-98 Can you perhaps update your version of Chrome to 99 and see if the problem persists? I tested with Version 99.0.4844.51

@Hill-98
Copy link
Author

Hill-98 commented Mar 15, 2022

The problem is still there, but I found the element causing the problem.
If I remove this element, the translation works fine: #sidebar-quicklinks > div > div:nth-child(3) > ol > li:nth-child(12) > details > ol > li:nth-child(2) > a

Likewise, the translation feature does not work at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor.

I think it has something to do with constructor.

@caugner
Copy link
Contributor

caugner commented Mar 15, 2022

@Hill-98 Would you mind filing an issue for this in the Chromium issue tracker? That would be great!

@Hill-98
Copy link
Author

Hill-98 commented Mar 15, 2022

@caugner

I have not used Chromium issue tracker and my English is not very good.

If you'd like to submit this issue in the Chromium issue tracker, that's certainly fine.

@github-actions github-actions bot added the 🐌 idle Issues and PRs without recent activity. Flagged for maintainer follow-up. label Apr 21, 2022
@github-actions github-actions bot added the idle label Dec 21, 2022
@mirunacurtean mirunacurtean added the localization i18n & l10n label Apr 23, 2024
@github-actions github-actions bot removed the idle label Apr 23, 2024
@github-actions github-actions bot added the idle label May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd-party Issues related to third-parties, such as Pocket or Google Translate ♿ a11y An MDN Web Docs accessible by everyone 🐌 idle Issues and PRs without recent activity. Flagged for maintainer follow-up. idle localization i18n & l10n p3 We don't have visibility when this will be addressed.
Projects
Development

Successfully merging a pull request may close this issue.

4 participants