Skip to content

fix(fr): translate issue.origin in too_big/too_small errors (fix #5825)#5845

Merged
colinhacks merged 2 commits into
colinhacks:mainfrom
Ouaziz-chedli:fix/fr-locale-issue-5825
Apr 28, 2026
Merged

fix(fr): translate issue.origin in too_big/too_small errors (fix #5825)#5845
colinhacks merged 2 commits into
colinhacks:mainfrom
Ouaziz-chedli:fix/fr-locale-issue-5825

Conversation

@Ouaziz-chedli

Copy link
Copy Markdown
Contributor

Summary
Fixed issue #5825 - French locale issue.origin not translated in too_big and too_small errors.
Problem
When using Zod's French locale (fr), error messages for too_big and too_small validations contained untranslated issue.origin values (e.g., "Trop grand : number doit être <=24" instead of "Trop grand : nombre doit être <=24").
Solution

  • Extended TypeDictionary in fr.ts to include all origin values: string, number, int, boolean, bigint, date, array, set, file, etc.
  • Updated too_big and too_small error cases to use TypeDictionary[issue.origin] for translation
  • Improved translations: set → "ensemble", map → "carte", record → "enregistrement", bigint → "grand entier"
    Files Changed
  • packages/zod/src/v4/locales/fr.ts - Fixed translations
  • packages/zod/src/v4/core/tests/locales/fr.test.ts - Added comprehensive tests
Screenshot 2026-04-08 at 22 57 58

The pluralization assertions used `toContain` where singulars are
substrings of plurals (e.g. "21 élément" inside "21 éléments"), so
they passed without testing pluralization (which fr.ts does not
implement). Replaced with the same focused style as `es.test.ts`:
exact-message assertions covering the actual fix — `issue.origin`
translation in `too_big`/`too_small` plus a sanity check on
`invalid_type`.
@colinhacks colinhacks merged commit 37ac1ba into colinhacks:main Apr 28, 2026
3 of 6 checks passed
@pullfrog

pullfrog Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

TL;DR — French locale error messages for too_big and too_small validations now translate issue.origin (e.g. "number" → "nombre") instead of embedding the raw English type name. Fixes #5825.

Key changes

  • Translate issue.origin via TypeDictionary in too_big/too_small cases — The too_big and too_small branches in the French error map now look up issue.origin in TypeDictionary (with a "valeur" fallback) instead of interpolating the raw English string.
  • Expand TypeDictionary with all origin types — Adds French translations for string, int, boolean, bigint, symbol, undefined, null, never, void, date, object, tuple, record, map, set, file, nonoptional, and function.
  • Add French locale tests — New test file covering too_small, too_big, and invalid_type error messages to verify type names are properly translated.

Summary | 2 files | 2 commits | base: mainfix/fr-locale-issue-5825


Before: too_big/too_small errors interpolated issue.origin directly, producing mixed-language messages like "Trop grand : number doit être <=24". too_small also lacked the ?? "valeur" fallback present in too_big.
After: Both cases resolve issue.origin through TypeDictionary, producing fully translated messages like "Trop grand : nombre doit être <=24". Both branches now include the "valeur" fallback for unknown origins.

The TypeDictionary — previously containing only nan, number, and array — is expanded to cover every $ZodInvalidTypeExpected variant. The too_big and too_small switch cases now use TypeDictionary[issue.origin] ?? "valeur" consistently, aligning the translation strategy with how invalid_type already resolved type names.

fr.ts · fr.test.ts

Pullfrog  | View workflow run | via Pullfrog | Using Claude Opus𝕏

colinhacks added a commit that referenced this pull request Apr 28, 2026
After #5845 added `string: "chaîne"` to the French TypeDictionary,
the resolution test fixture (which checks the safeParse output under
the `fr` locale) was still asserting the pre-translation message
"Entrée invalide : string attendu, nombre reçu". CI on main has been
red since 37ac1ba. Update all three entrypoints (`index.ts`,
`index.cts`, `index.mts`) to match the actual translated output.
@colinhacks

Copy link
Copy Markdown
Owner

Merged. Trimmed the test file in 03cab505 before landing — the pluralization assertions used toContain where singulars are substrings of plurals (e.g. "21 élément" inside "21 éléments"), so they passed without actually testing pluralization, which fr.ts doesn't implement. Replaced with exact-message checks in the style of es.test.ts covering the real fix in too_big/too_small plus a sanity check on invalid_type. Thanks for tracking down #5825 👍

Note: this comment was produced by an AI coding assistant.

@colinhacks

Copy link
Copy Markdown
Owner

Landed in Zod 4.4

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.

2 participants