Repository navigation
Localize validation errors of the dashboard API - #300
Merged
Merged
Conversation
Thirteen dashboard routes answered a rejected body with the first zod
issue's message, so every language saw English: our own schema texts
("Enter a valid Discord ID.") as well as zod's built-in ones.
The custom messages now live as constants in VALIDATION_MESSAGES
(packages/shared) and the schemas use them. validationMessage() in
lib/validation-error.ts maps a message back to its key and answers from
the new `validation` dictionary section; zod's built-in messages come
from zod's own locales. A wrong type gets a generic text, because a
finished issue no longer has the input and zod would claim it received
"undefined". The public REST API (api/v1) stays English on purpose.
"Duplicate key." reads "Each key can only be used once." now, and the
category colour message uses the same example as the others.
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.
Problem
13 dashboard routes returned
parsed.error.issues[0]?.messageas theerrorof their 422, and the forms show that text as is. A German or Polish owner saw "Enter a valid Discord ID." or zod's own "Too big: expected string to have <=80 characters".Fix
packages/shared/src/validation-messages.ts: the 13 custom messages of our schemas as constants (VALIDATION_MESSAGES) plusvalidationMessageKey()for the reverse lookup. The schemas inaudit-log,bot-config,branding,categories,domains,form-definition,form-settings,handle,status-defsandwebhooksuse the constants instead of inline text.apps/web/src/lib/validation-message.ts(pure, tested): our own message →validationdictionary entry. A built-in zod message → zod's locale for de, hu, fr, es, pt, pl.invalid_type→ a generic "This value isn't valid.", because a finished issue no longer carries the input and zod's text would say "received undefined".apps/web/src/lib/validation-error.ts:validationMessage(error)reads the locale and dictionary of the request. The 13 routes call it instead of reading the issue directly.validationsection in all seven dictionaries.Dictionary = typeof enplus the key type make a missing translation a compile error.api/v1/hookskeeps English on purpose. It's the public REST API for integrations.#00E676) as branding and statuses.Tests
validation-message.test.ts: own message translated, English untouched, zod's German for a built-in issue, generic text for a wrong type, every key present in every language.pnpm --filter @msk-forms/sharedand@msk-forms/web: typecheck and tests (107 and 322) green, eslint on the changed files.