Open Bug 1855260 Opened 1 year ago Updated 1 year ago

Listen for when the document's html lang attribute is changed

Categories

(Firefox :: Translations, defect, P3)

Firefox 118
defect

Tracking

()

People

(Reporter: epavlov, Unassigned)

Details

Steps to reproduce:

  1. Go to German Wikipedia https://de.wikipedia.org/wiki/Wikipedia:Hauptseite
  2. Enable automatic translation from German to English in the popup menu
  3. Go to DW in German (choose the language in the hamburger menu if needed) https://www.dw.com/de/themen/s-9077
  4. Navigate to any page

Expected:

  1. The page was translated right after switching the language
  2. The pages are translated while browsing the website

Actual:

  1. I have to reload the web pages to translate automatically

I can't reproduce myself, when I navigate to https://www.dw.com/de/themen/s-9077 it is automatically translated.

This is a case where the language is changed by JavaScript. We should probably come up with a better strategy to handle when a page changes the language tag.

Here is the page source:

<!doctype html>
<html lang="en">
<head>
  ...
  <script type="module" crossorigin src="/static/index-82437323.js"></script>
  <link rel="stylesheet" href="/static/index-ef709cb8.css">
</head>

<body>
  <noscript>
    You need to enable JavaScript to run this app.
  </noscript>
  <div id="root"></div>
  
</body>

</html>

While the live page with JS is:

<html lang="de" data-rh="lang">

The TranslationsChild checks this at DOMContentLoaded, although maybe we should wait a micro-tick to allow a page to win the race of who's DOMContentLoaded fires first.

  handleEvent(event) {
    switch (event.type) {
      case "DOMContentLoaded":
        this.innerWindowId =
          this.contentWindow?.windowGlobalChild.innerWindowId;
        this.sendAsyncMessage("Translations:ReportLangTags", {
          documentElementLang: this.document.documentElement.lang,
        });
        break;
    }
  }

To further complicate things, in Bug 1840857 I am moving this code to C++, which is may be trickier to find a good hook for when things change.

What's even worse here is that we may automatically translate FROM English for someone, which will be another "Language Degradation Machine".

I can't reproduce myself

It's a race condition and is only intermittently reproduceable.

The severity field is not set for this bug.
:nordzilla, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(enordin)
Severity: -- → S3
Priority: -- → P3
Summary: Automatic translation does not work on Deutsche Welle website → Listen for when the document's html lang attribute is changed
Flags: needinfo?(enordin)

I changed this bug to be about listening for the lang tag changing. I'm not 100% sure what we should do for cases like this, as it could lead to a situation where we offer an English translation, and then offer a German one.

You need to log in before you can comment on or make changes to this bug.