Repository navigation
fix(i18n): check placeholder and tag parity in i18n:check - #42532
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
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.
9bc1b91 to
630a2c2
Compare
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]>
630a2c2 to
4a8cad3
Compare

Summary
scripts/check-i18n.jscompares 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.ymlinstructs its agent: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.tscompares the values of keys present in both the en-US file and the locale file, and reports two kinds of mismatch:{{name}},{{count,number}}and${name}.<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:
The script now exits non-zero for a value mismatch as well as a key mismatch. Scoping is unchanged —
--fileand--langnarrow 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:
MM/DD/YYYYbecameMM/TT/JJJJinde-DE,JJ/MM/AAAAinfr-FR,DD/MM/RRRRinpl-PL,ДД/ММ/ГГГГinru-RU. Every mechanical rule I tried either flagged legitimate localizations (ja-JPusesYYYY 年 M 月 D 日, which dayjs renders correctly) or missed cases where the substituted letters happen to be valid tokens (ro-RO'sZZ/LL/AAAA). Picking the correct format per locale is a call for the people who own those languages.zh-*,ja-JPandko-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
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 usedvp checkrather thanvp staged, which has nostagedconfig in the repo'svite.config.ts.tsx ./scripts/check-i18n.jsacross all locales —✅ All i18n files are in sync.{{version}}from onetr-TRvalue 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.