fix(translations): add i18n support to checkFileRestrictions error messages#16344
Open
fglowicki wants to merge 3 commits intopayloadcms:mainfrom
Open
fix(translations): add i18n support to checkFileRestrictions error messages#16344fglowicki wants to merge 3 commits intopayloadcms:mainfrom
fglowicki wants to merge 3 commits intopayloadcms:mainfrom
Conversation
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".
81884b2 to
e56f7fe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Upload validation errors in
checkFileRestrictions.tswere always displayedin 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
twas never passed to theValidationErrorconstructor.
Why?
checkFileRestrictions.tsalready receivesreq(which carriesreq.t) butnever 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?
tfromreqat the top ofcheckFileRestrictionst('upload:...')callstas the second argument to eachValidationErrorconstructor sothe toast prefix ("The following field is invalid:") is also translated
en.tsand auto-translatethem to all 44 supported languages using the existing translation pipeline
mockReqin existing unit tests to include thetfunction, whichwas now required after the refactor