fix(l10n): silence spurious 'could not translate element content' warning on form controls#7797
Conversation
…warning) `<select data-l10n-id="...">` with `<option>` element children — the pattern used by ep_headings2, ep_align, ep_font_size, ep_font_family, … — used to drop into the textContent branch of html10n.translateNode and hunt for a text-node child to overwrite. There is none, so the loop exited with `found = false` and emitted: Unexpected error: could not translate element content for key ep_headings.style The SELECT/INPUT/TEXTAREA aria-label fallback already lived inside the same else-branch, *after* the warning, so the accessible name landed correctly but the noisy console line still fired on every pad load. Move the form-control case into its own `else if`, before the text-node hunt: aria-label is the only sensible localization target for these elements (a <select>'s text is its <option> labels, not its own name). Closes the console warning reported on Etherpad 3.1.0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Review Summary by QodoSuppress spurious warning for form controls with data-l10n-id
WalkthroughsDescription• Eliminate spurious "could not translate element content" warning for form controls - Move form-control case (<select>, <input>, <textarea>) into separate branch before text-node hunt - Prevents warning when elements have only <option> children instead of text nodes • Add regression test for <select data-l10n-id> warning suppression - Verifies no console warning emitted during localization - Ensures aria-label still populated correctly on form controls Diagramflowchart LR
A["translateNode called<br/>on form control"] --> B{"Check if SELECT/<br/>INPUT/TEXTAREA"}
B -->|Yes| C["Populate aria-label<br/>only"]
B -->|No| D["Hunt for text-node<br/>child"]
D -->|Found| E["Update textContent"]
D -->|Not found| F["Warn about missing<br/>element content"]
C --> G["No spurious warning"]
E --> G
File Changes1. src/static/js/vendors/html10n.ts
|
Code Review by Qodo
1.
|
Qodo's review on #7797 caught two real test bugs: 1. `pad.toolbar.bold.title` ends in `.title`, which is in html10n's attribute allowlist. translateNode picks `prop = 'title'`, takes the first branch (node[prop] = str.str), and never reaches the textContent path where the warning lives. The test would pass without my fix. Switched the key to `pad.loading` — same stable pad-bundle translation, but the suffix isn't in the allowlist, so `prop` defaults to `textContent` and the test actually exercises the regression path. 2. `page.waitForTimeout(50)` is a fixed sleep, but `html10n.localize` runs its work inside a `build()` callback, so completion timing depends on the loader. Replaced with a deterministic `html10n.mt .bind('localized', …)` await. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
<select data-l10n-id="…">with<option>element children (ep_headings2, ep_align, ep_font_size, ep_font_family, …) used to printUnexpected error: could not translate element content for key …on every pad load. The textContent branch inhtml10n.translateNodehunted for a text-node child, found none, and warned — even though the existing SELECT/INPUT/TEXTAREA aria-label fallback further down still set the accessible name correctly.else if, before the text-node hunt.aria-labelis the only sensible localization target for<select>/<input>/<textarea>(their text is on<option>/value, not directly on the control).<select data-l10n-id>and asserts nocould not translate element contentwarning is emitted.Reported by thm on Etherpad 3.1.0:
Existing aria-label population (PR #7584) is unchanged in observable behaviour; the new test alongside it locks in that the warning stays silent.
Test plan
tsc --noEmitcleanhtml10n_form_controls_aria.spec.ts → 'no "could not translate element content" warning for <select data-l10n-id>'html10n_form_controls_aria.spec.tsstill pass🤖 Generated with Claude Code