Closed Bug 1842804 Opened 2 years ago Closed 2 years ago

Set lang attribute to the translated language after translation

Categories

(Firefox :: Translations, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
123 Branch
Tracking Status
firefox123 --- fixed

People

(Reporter: marco, Assigned: wartmanm)

Details

Attachments

(1 file)

It looks like Google Translate and Safari Translate do this as well, according to https://github.com/mozilla/firefox-translations/issues/727.

This is probably an accessibility thing as well, although I don't think macOS VoiceOver supports multilingual voices. It's quite comical testing VoiceOver on Spanish pages with an English voice.

Following this over from Github. As I mentioned over there, I'd be happy to implement this. I have some experience contributing to Firefox already, albeit on my personal account.

That would be great! Let me know if you need any pointers.

The translations document is where this will need to happen:

https://searchfox.org/mozilla-central/rev/0ba4632ee85679a1ccaf652df79c971fa7e9b9f7/toolkit/components/translations/content/translations-document.sys.mjs#763-793

I think the existing tests will just need to be updated, and no new ones created:

https://searchfox.org/mozilla-central/rev/0ba4632ee85679a1ccaf652df79c971fa7e9b9f7/toolkit/components/translations/tests/browser/browser_translations_translation_document.js

Care will need to be taken for what happens with bare text nodes, as a parent element may need to be modified. I haven't thought through this completely though. It might be good to test other implementations.

We also have lots of Outreachy applicants picking up translations bugs this month, so we're only assigning bugs right now when there is a patch up.

I hadn't really considered how arbitrary nodes might need to be updated, that makes things trickier.

I did some more testing, and Safari and Chrome modify the root <html lang="..."> attribute if one is present, but don't add one. They don't seem to update lang attributes on other elements, or to pay any attention to them for translation purposes. Edge doesn't modify lang attributes at all.

Since Firefox does honor lang attributes, would it be appropriate to update them (so long as they match the source language) but follow suit and not add new ones?

Flags: needinfo?(gtatum)

Let's make it simple. I would say we should only modify the <html> lang attribute once we do a full page translation into that language. I can verify that Safari and Chrome modify the root HTML. If we get more complicated with translating subroots of the page or selection translation in place, we can revisit this then.

Flags: needinfo?(gtatum)
Assignee: nobody → wartmanm
Status: NEW → ASSIGNED

I used the existing viewportTranslated promise rather than adding a new one to wait for the full page translation, as it seemed like it was in the same spirit and I didn't want to make it more complex. I can add a fullPageTranslated promise if desired, though.

That being said, viewportTranslated seems to be firing too early, when the title node is translated rather than body. Should I file a separate bug to address that?

That being said, viewportTranslated seems to be firing too early, when the title node is translated rather than body. Should I file a separate bug to address that?

Yeah it would be good to get that fixed if that's the case! We're only using it for telemetry purposes at this moment.

There is an r+ patch which didn't land and no activity in this bug for 2 weeks.
:wartmanm, could you have a look please?
If you still have some work to do, you can add an action "Plan Changes" in Phabricator.
For more information, please visit BugBot documentation.

Flags: needinfo?(wartmanm)
Flags: needinfo?(gtatum)

I plan on landing this on Monday after the soft freeze.

Flags: needinfo?(wartmanm)

So I tried to land it before the break, and unfortunately it needs rebasing. I'm not sure how I can do that myself. Sorry for the really long process here, but would you mind seeing if you can do that :mattheww?

Flags: needinfo?(gtatum) → needinfo?(wartmanm)

Sorry for disappearing! It's rebased and should be ready to go.

This has been a bit of "action at a distance", but I hit land! Let's hope it sticks. Thanks for the contribution.

Pushed by gtatum@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2c7ee2513bf0 Update lang attribute after translating page r=gregtatum,translations-reviewers
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 123 Branch
Flags: needinfo?(wartmanm)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: