Skip to content

fix(translations): add i18n support to checkFileRestrictions error messages#16344

Open
fglowicki wants to merge 3 commits intopayloadcms:mainfrom
fglowicki:fix/i18n-check-file-restrictions
Open

fix(translations): add i18n support to checkFileRestrictions error messages#16344
fglowicki wants to merge 3 commits intopayloadcms:mainfrom
fglowicki:fix/i18n-check-file-restrictions

Conversation

@fglowicki
Copy link
Copy Markdown

@fglowicki fglowicki commented Apr 22, 2026

What?

Upload validation errors in checkFileRestrictions.ts were always displayed
in English, regardless of the user's chosen admin language. This affected 7
error messages covering invalid MIME types, restricted file types, malicious
SVG content, corrupted PDFs, and file read failures.

Additionally, the "The following field is invalid:" toast prefix was also
permanently English because t was never passed to the ValidationError
constructor.

Why?

checkFileRestrictions.ts already receives req (which carries req.t) but
never used it for error messages. Upload validation errors are user-facing and
should respect the admin language setting like every other error in the system.

How?

  • Destructure t from req at the top of checkFileRestrictions
  • Replace all 7 hardcoded English strings with t('upload:...') calls
  • Pass t as the second argument to each ValidationError constructor so
    the toast prefix ("The following field is invalid:") is also translated
  • Add 7 new keys to the `upload` namespace in en.ts and auto-translate
    them to all 44 supported languages using the existing translation pipeline
  • Fix mockReq in existing unit tests to include the t function, which
    was now required after the refactor

Add 7 new keys to the upload namespace across all 44 language files:
couldNotReadFileForTypeDetection, couldNotReadFileForValidation,
fileTypeNotAllowed, invalidMimeType, invalidOrCorruptedPDF,
restrictedFileType, svgHarmfulContent.
…s with i18n

Destructure t from req and replace all 7 hardcoded English error strings
with req.t() calls. Pass t as second argument to each ValidationError
constructor so the "The following field is invalid:" prefix is also
translated according to the user's chosen admin language.
mockReq was missing the t function required by checkFileRestrictions
after the i18n refactor, causing tests to throw "t is not a function".
@fglowicki fglowicki force-pushed the fix/i18n-check-file-restrictions branch from 81884b2 to e56f7fe Compare April 22, 2026 06:41
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.

1 participant