Skip to content

[WIP] Fix split string suggestion labels to improve translator flexibility#415

Draft
Copilot wants to merge 1 commit into
mainfrom
copilot/fix-split-string-suggestion-labels
Draft

[WIP] Fix split string suggestion labels to improve translator flexibility#415
Copilot wants to merge 1 commit into
mainfrom
copilot/fix-split-string-suggestion-labels

Conversation

Copy link
Copy Markdown

Copilot AI commented May 13, 2026

Thanks for asking me to work on this. I will get started on it and keep this PR's description up to date as I form a plan and make progress.


This section details on the original issue you should resolve

<issue_title>i18n: split-string suggestion labels reduce translator flexibility</issue_title>
<issue_description>## Background
PRs #369 and #378 fixed user-visible bugs where the suggestion form / sidebar rendered literal `{{changeFrom}}` placeholders. The fix in both cases was to split the original sentence

Suggested change from "{{changeFrom}}" to "{{changeTo}}"

into three pieces — a `_from_label` key ("Suggested change from"), the value span, a `_to_label` key ("to"), and the second value span — because html10n's `data-l10n-args` substitution wasn't reliably replacing `{{…}}` placeholders.

Why this is suboptimal

Splitting the sentence costs translator flexibility. Languages with verb-final word order, RTL flow, or different "from … to …" idioms can no longer reorder the values relative to the surrounding text — the DOM order is fixed.

Root cause to investigate

`vendors/html10n.ts` line ~631 does `JSON.parse(node.getAttribute('data-l10n-args'))` with no try/catch. If the selected text contains a quote or backslash, jquery.tmpl's `${changeFrom}` substitution produces invalid JSON and the parse throws — html10n then renders the unsubstituted `{{changeFrom}}` (or fails silently depending on the call site).

Suggested fix

  1. Wrap the `JSON.parse` in a try/catch with a console.warn fallback so a single broken element doesn't break the whole element list.
  2. Build `data-l10n-args` from JS rather than from the template (e.g. `$el.attr('data-l10n-args', JSON.stringify({changeFrom: selectedText}))` after tmpl render) so the values are always valid JSON-encoded strings.
  3. Once that's reliable, reunify the split keys back into the original single-string translations and delete the `_from_label` / `_to_label` workaround keys.

Scope

  • `templates/comments.html` — display-suggestion + new-comment-form blocks
  • `static/js/index.js`, `static/js/newComment.js`, `static/js/index.js#displayNewCommentForm` — set data-l10n-args at runtime
  • `locales/en.json` — restore single-string keys, deprecate split keys
  • Coordinate with translatewiki sweep so existing translations of the original `suggested_change_from` / `suggest_change_from` keys are reused</issue_description>

Comments on the Issue (you are @copilot in this section)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

i18n: split-string suggestion labels reduce translator flexibility

2 participants