Skip to content

fix(i18n): check placeholder and tag parity in i18n:check - #42532

Merged
crazywoola merged 1 commit into
langgenius:mainfrom
bakiburakogun:fix/i18n-check-placeholder-parity
Sep 21, 2026
Merged

crazywoola merged 1 commit into
langgenius:mainfrom
bakiburakogun:fix/i18n-check-placeholder-parity

Conversation

@bakiburakogun

@bakiburakogun bakiburakogun commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

scripts/check-i18n.js compares key sets and nothing else. A locale file can drop, rename or invent an interpolation variable and the check still reports the locale as in sync, because no code path ever looks at a value.

That gap sits directly under the translation sync workflow. translate-i18n-claude.yml instructs its agent:

Preserve placeholders exactly: {{variable}}, ${variable}, HTML tags, component tags, and variable names.

and then, in step 6, has it verify the result with vp run dify-web#i18n:check — the one check that cannot tell whether the instruction was followed. So the rule is stated on every run and verified on none.

When it goes wrong the user sees it directly: either a raw {{name}} rendered into the UI, or a sentence quietly missing the value it was meant to carry — a password reset notice that no longer names the address it went to reads fine in review and is useless in production.

What this adds

scripts/check-i18n-values.ts compares the values of keys present in both the en-US file and the locale file, and reports two kinds of mismatch:

  • Interpolation variables — {{name}}, {{count,number}} and ${name}.
  • Markup tags — the <bold> / <techLink> style elements handed to <Trans>, and plain HTML inside values.

Both are compared as multisets, so a translation is free to reorder them to suit its word order — {{total}} içinden {{used}} kullanıldı is accepted — while a dropped, added, renamed or duplicated one is reported. Keys that are missing from a locale are left alone; the existing key-level report already owns those and listing them twice would bury the value problems.

Output names the file, the key and both sides:

Placeholder and tag mismatches in tr-TR:
  common.about.latestAvailable: expected placeholders {{version}}, found (none)

The script now exits non-zero for a value mismatch as well as a key mismatch. Scoping is unchanged — --file and --lang narrow the value pass the same way they narrow the key pass, so the workflow's scoped verification step picks this up with no change to the workflow itself.

This lands green

All 25 supported locales pass today: I ran the full check across every locale and found no placeholder or tag mismatch. So this is a regression guard from day one, not a backlog to work off.

Deliberately not included

Two related classes came up while measuring this, and both need a decision this PR should not make on its own:

  • Translated date-format tokens — 37 values across 10+ locales have had their dayjs tokens translated, so they render as literal text instead of a date: MM/DD/YYYY became MM/TT/JJJJ in de-DE, JJ/MM/AAAA in fr-FR, DD/MM/RRRR in pl-PL, ДД/ММ/ГГГГ in ru-RU. Every mechanical rule I tried either flagged legitimate localizations (ja-JP uses YYYY 年 M 月 D 日, which dayjs renders correctly) or missed cases where the substituted letters happen to be valid tokens (ro-RO's ZZ/LL/AAAA). Picking the correct format per locale is a call for the people who own those languages.
  • Lost leading/trailing spaces on fragments the UI concatenates — about 1000 values diverge from their source here, but dropping a boundary space is often correct for zh-*, ja-JP and ko-KR, so a parity rule would be wrong for them.

Happy to follow up on either if you'd like them tracked.

Screenshots

Not applicable — this changes a CLI check with no UI surface.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly.
  • I ran the frontend lint gods' checks — see below.

Verification

  • vp test run --project unit scripts/__tests__/check-i18n-values.spec.ts — 9 passed. Covers a clean translation, a dropped placeholder, a renamed one, an invented one, a dropped tag, reordering, a repeated placeholder appearing a different number of times, and keys absent from the locale.
  • vp check scripts/check-i18n-values.ts scripts/check-i18n.js scripts/__tests__/check-i18n-values.spec.ts — formatting, lint and types all clean. I used vp check rather than vp staged, which has no staged config in the repo's vite.config.ts.
  • tsx ./scripts/check-i18n.js across all locales — ✅ All i18n files are in sync.
  • To confirm it actually catches the regression, I removed {{version}} from one tr-TR value and re-ran the scoped check: the key comparison still reported { 'tr-TR': 0 }, while the new value check reported the mismatch and exited 1. That contrast is the bug this fixes.

No locale file is changed by this PR.

@github-actions github-actions Bot added the web This relates to changes on the web. label Sep 18, 2026
@codecov

codecov Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.54%. Comparing base (f12a876) to head (4a8cad3).
⚠️ Report is 27 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #42532    +/-   ##
========================================
  Coverage   87.53%   87.54%            
========================================
  Files        5468     5470     +2     
  Lines      316733   316883   +150     
  Branches    63517    63518     +1     
========================================
+ Hits       277265   277400   +135     
- Misses      34098    34113    +15     
  Partials     5370     5370            
Flag Coverage Δ
dify-ui 91.85% <ø> (-1.27%) ⬇️
web 87.96% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Present non-string translations can bypass marker validation while passing the key check.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Adds value-level i18n validation to prevent placeholder and markup drift across locales.

Changes:

  • Compares placeholders and tags as multisets.
  • Integrates value mismatches into i18n:check.
  • Adds focused unit coverage.
File Description
web/​scripts/​check-i18n.js Runs value parity checks alongside key checks.
web/​scripts/​check-i18n-values.ts Extracts and compares placeholders and tags.
web/​scripts/​__tests__/​check-i18n-values.spec.ts Tests parity detection and reporting.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread web/scripts/check-i18n-values.ts Resolved
@bakiburakogun
bakiburakogun force-pushed the fix/i18n-check-placeholder-parity branch from 9bc1b91 to 630a2c2 Compare September 20, 2026 03:04
check-i18n.js compares key sets only. A locale file can drop, rename or
invent an interpolation variable and still pass, because nothing ever
looks at the values.

That gap sits right under the translation sync workflow. Its prompt tells
the agent to preserve placeholders exactly, and step 6 has it verify the
result with this same script — which cannot see the difference. When it
goes wrong the user gets either a raw {{name}} rendered into the UI, or a
sentence quietly missing the value it was meant to carry, such as a
password reset notice that no longer names the address it went to.

This compares the values of keys present in both files and reports a
mismatch in the interpolation variables ({{x}}, {{count,number}}, ${x})
or in the markup tags handed to <Trans>. Both are compared as multisets,
so reordering them to suit the target language is fine while a dropped,
added or renamed one is not. Keys missing from a locale are left to the
existing key-level report rather than counted twice.

All 25 supported locales pass today, so this lands green and works as a
regression guard rather than a backlog.

Signed-off-by: Baki Burak Öğün <[email protected]>
@bakiburakogun
bakiburakogun force-pushed the fix/i18n-check-placeholder-parity branch from 630a2c2 to 4a8cad3 Compare September 20, 2026 04:36
@crazywoola
crazywoola added this pull request to the merge queue Sep 21, 2026
Merged via the queue into langgenius:main with commit ee0efe0 Sep 21, 2026
47 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants