-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add de, es, fr, pt-br, pt-pt locales (#3637)
- Loading branch information
Showing
5 changed files
with
842 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import { type ZodErrorMap, ZodIssueCode } from "../ZodError"; | ||
import { util } from "../helpers"; | ||
|
||
const errorMap: ZodErrorMap = (issue, _ctx) => { | ||
let message: string; | ||
switch (issue.code) { | ||
case ZodIssueCode.invalid_type: | ||
if (issue.received === util.ZodParsedType.undefined) { | ||
message = "Darf nicht leer sein"; | ||
} else { | ||
message = `${issue.expected} erwartet, ${issue.received} erhalten`; | ||
} | ||
break; | ||
case ZodIssueCode.invalid_literal: | ||
message = `Ungültiger Literalwert, ${JSON.stringify( | ||
issue.expected, | ||
util.jsonStringifyReplacer | ||
)} erwartet`; | ||
break; | ||
case ZodIssueCode.unrecognized_keys: | ||
message = `Unbekannte Schlüssel im Objekt: ${util.joinValues( | ||
issue.keys, | ||
", " | ||
)}`; | ||
break; | ||
case ZodIssueCode.invalid_union: | ||
message = `Ungültige Eingabe`; | ||
break; | ||
case ZodIssueCode.invalid_union_discriminator: | ||
message = `Ungültiger Diskriminatorwert, ${util.joinValues( | ||
issue.options | ||
)} erwartet`; | ||
break; | ||
case ZodIssueCode.invalid_enum_value: | ||
message = `Ungültiger Enum-Wert. ${util.joinValues( | ||
issue.options | ||
)} erwartet, '${issue.received}' erhalten`; | ||
break; | ||
case ZodIssueCode.invalid_arguments: | ||
message = `Ungültige Funktionsargumente`; | ||
break; | ||
case ZodIssueCode.invalid_return_type: | ||
message = `Ungültiger Funktionsrückgabewert`; | ||
break; | ||
case ZodIssueCode.invalid_date: | ||
message = `Ungültiges Datum`; | ||
break; | ||
case ZodIssueCode.invalid_string: | ||
if (typeof issue.validation === "object") { | ||
if ("includes" in issue.validation) { | ||
message = `Ungültige Eingabe: muss "${issue.validation.includes}" enthalten`; | ||
if (typeof issue.validation.position === "number") { | ||
message = `${message} an einer oder mehreren Positionen größer oder gleich ${issue.validation.position}`; | ||
} | ||
} else if ("startsWith" in issue.validation) { | ||
message = `Ungültige Eingabe: muss mit "${issue.validation.startsWith}" beginnen`; | ||
} else if ("endsWith" in issue.validation) { | ||
message = `Ungültige Eingabe: muss mit "${issue.validation.endsWith}" enden`; | ||
} else { | ||
util.assertNever(issue.validation); | ||
} | ||
} else if (issue.validation !== "regex") { | ||
message = `Ungültige ${issue.validation}`; | ||
} else { | ||
message = "Ungültig"; | ||
} | ||
break; | ||
case ZodIssueCode.too_small: | ||
if (issue.type === "array") | ||
message = `Array muss ${ | ||
issue.exact ? "genau" : issue.inclusive ? `mindestens` : `mehr als` | ||
} ${issue.minimum} Element(e) enthalten`; | ||
else if (issue.type === "string") | ||
message = `String muss ${ | ||
issue.exact ? "genau" : issue.inclusive ? `mindestens` : `mehr als` | ||
} ${issue.minimum} Zeichen enthalten`; | ||
else if (issue.type === "number") | ||
message = `Zahl muss ${ | ||
issue.exact | ||
? `genau` | ||
: issue.inclusive | ||
? `größer oder gleich` | ||
: `größer als` | ||
} ${issue.minimum} sein`; | ||
else if (issue.type === "date") | ||
message = `Datum muss ${ | ||
issue.exact | ||
? `genau` | ||
: issue.inclusive | ||
? `größer oder gleich` | ||
: `größer als` | ||
} ${new Date(Number(issue.minimum))} sein`; | ||
else message = "Ungültige Eingabe"; | ||
break; | ||
case ZodIssueCode.too_big: | ||
if (issue.type === "array") | ||
message = `Array muss ${ | ||
issue.exact ? `genau` : issue.inclusive ? `höchstens` : `weniger als` | ||
} ${issue.maximum} Element(e) enthalten`; | ||
else if (issue.type === "string") | ||
message = `String muss ${ | ||
issue.exact ? `genau` : issue.inclusive ? `höchstens` : `weniger als` | ||
} ${issue.maximum} Zeichen enthalten`; | ||
else if (issue.type === "number") | ||
message = `Zahl muss ${ | ||
issue.exact | ||
? `genau` | ||
: issue.inclusive | ||
? `kleiner oder gleich` | ||
: `kleiner als` | ||
} ${issue.maximum} sein`; | ||
else if (issue.type === "bigint") | ||
message = `Bigint muss ${ | ||
issue.exact | ||
? `genau` | ||
: issue.inclusive | ||
? `kleiner oder gleich` | ||
: `kleiner als` | ||
} ${issue.maximum} sein`; | ||
else if (issue.type === "date") | ||
message = `Datum muss ${ | ||
issue.exact | ||
? `genau` | ||
: issue.inclusive | ||
? `kleiner oder gleich` | ||
: `kleiner als` | ||
} ${new Date(Number(issue.maximum))} sein`; | ||
else message = "Ungültige Eingabe"; | ||
break; | ||
case ZodIssueCode.custom: | ||
message = `Ungültige Eingabe`; | ||
break; | ||
case ZodIssueCode.invalid_intersection_types: | ||
message = `Schnittmengenergebnisse konnten nicht zusammengeführt werden`; | ||
break; | ||
case ZodIssueCode.not_multiple_of: | ||
message = `Zahl muss ein Vielfaches von ${issue.multipleOf} sein`; | ||
break; | ||
case ZodIssueCode.not_finite: | ||
message = "Zahl muss endlich sein"; | ||
break; | ||
case ZodIssueCode.uniqueness: | ||
message = issue.duplicateElements?.length | ||
? `Element(e): '${issue.duplicateElements}' nicht eindeutig` | ||
: "Werte müssen eindeutig sein"; | ||
break; | ||
case ZodIssueCode.invalid_file_type: | ||
message = `Ungültiger Dateityp. ${util.joinValues( | ||
issue.expected | ||
)} erwartet, '${issue.received}' erhalten`; | ||
break; | ||
case ZodIssueCode.invalid_file_name: | ||
message = `Ungültiger Dateiname`; | ||
break; | ||
default: | ||
message = _ctx.defaultError; | ||
util.assertNever(issue); | ||
} | ||
return { message }; | ||
}; | ||
|
||
export default errorMap; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import { type ZodErrorMap, ZodIssueCode } from "../ZodError"; | ||
import { util } from "../helpers"; | ||
|
||
const errorMap: ZodErrorMap = (issue, _ctx) => { | ||
let message: string; | ||
switch (issue.code) { | ||
case ZodIssueCode.invalid_type: | ||
if (issue.received === util.ZodParsedType.undefined) { | ||
message = "Requerido"; | ||
} else { | ||
message = `Se esperaba ${issue.expected}, se recibió ${issue.received}`; | ||
} | ||
break; | ||
case ZodIssueCode.invalid_literal: | ||
message = `Valor literal inválido, se esperaba ${JSON.stringify( | ||
issue.expected, | ||
util.jsonStringifyReplacer | ||
)}`; | ||
break; | ||
case ZodIssueCode.unrecognized_keys: | ||
message = `Llave(s) no reconocida(s) en el objeto: ${util.joinValues( | ||
issue.keys, | ||
", " | ||
)}`; | ||
break; | ||
case ZodIssueCode.invalid_union: | ||
message = `Entrada inválida`; | ||
break; | ||
case ZodIssueCode.invalid_union_discriminator: | ||
message = `Valor discriminador inválido. Se esperaba ${util.joinValues( | ||
issue.options | ||
)}`; | ||
break; | ||
case ZodIssueCode.invalid_enum_value: | ||
message = `Valor inválido. Se esperaba ${util.joinValues( | ||
issue.options | ||
)}, se recibió '${issue.received}'`; | ||
break; | ||
case ZodIssueCode.invalid_arguments: | ||
message = `Argumentos de función inválidos`; | ||
break; | ||
case ZodIssueCode.invalid_return_type: | ||
message = `Tipo de retorno de función inválido`; | ||
break; | ||
case ZodIssueCode.invalid_date: | ||
message = `Fecha inválida`; | ||
break; | ||
case ZodIssueCode.invalid_string: | ||
if (typeof issue.validation === "object") { | ||
if ("includes" in issue.validation) { | ||
message = `Entrada inválida: debe incluir "${issue.validation.includes}"`; | ||
if (typeof issue.validation.position === "number") { | ||
message = `${message} en una o más posiciones mayores o iguales a ${issue.validation.position}`; | ||
} | ||
} else if ("startsWith" in issue.validation) { | ||
message = `Entrada inválida: debe comenzar con "${issue.validation.startsWith}"`; | ||
} else if ("endsWith" in issue.validation) { | ||
message = `Entrada inválida: debe finalizar con "${issue.validation.endsWith}"`; | ||
} else { | ||
util.assertNever(issue.validation); | ||
} | ||
} else if (issue.validation !== "regex") { | ||
message = `${issue.validation} inválido`; | ||
} else { | ||
message = "Inválido"; | ||
} | ||
break; | ||
case ZodIssueCode.too_small: | ||
if (issue.type === "array") | ||
message = `La lista debe contener ${ | ||
issue.exact ? "exactamente" : issue.inclusive ? `al menos` : `más de` | ||
} ${issue.minimum} elemento(s)`; | ||
else if (issue.type === "string") | ||
message = `El texto debe contener ${ | ||
issue.exact ? "exactamente" : issue.inclusive ? `al menos` : `más de` | ||
} ${issue.minimum} carácter(es)`; | ||
else if (issue.type === "number") | ||
message = `El número debe ser ${ | ||
issue.exact | ||
? `exactamente` | ||
: issue.inclusive | ||
? `mayor o igual a` | ||
: `mayor que` | ||
} ${issue.minimum}`; | ||
else if (issue.type === "date") | ||
message = `La fecha debe ser ${ | ||
issue.exact | ||
? `exactamente` | ||
: issue.inclusive | ||
? `mayor o igual al` | ||
: `mayor que el` | ||
} ${new Date(Number(issue.minimum))}`; | ||
else message = "Entrada inválida"; | ||
break; | ||
case ZodIssueCode.too_big: | ||
if (issue.type === "array") | ||
message = `La lista debe contener ${ | ||
issue.exact | ||
? `exactamente` | ||
: issue.inclusive | ||
? `como máximo` | ||
: `menos que` | ||
} ${issue.maximum} elemento(s)`; | ||
else if (issue.type === "string") | ||
message = `El texto debe contener ${ | ||
issue.exact | ||
? `exactamente` | ||
: issue.inclusive | ||
? `como máximo` | ||
: `menos de` | ||
} ${issue.maximum} carácter(es)`; | ||
else if (issue.type === "number") | ||
message = `El número debe ser ${ | ||
issue.exact | ||
? `exactamente` | ||
: issue.inclusive | ||
? `menor o igual a` | ||
: `menor que` | ||
} ${issue.maximum}`; | ||
else if (issue.type === "bigint") | ||
message = `El entero grande debe ser ${ | ||
issue.exact | ||
? `exactamente` | ||
: issue.inclusive | ||
? `menor o igual a` | ||
: `menor que` | ||
} ${issue.maximum}`; | ||
else if (issue.type === "date") | ||
message = `La fecha debe ser ${ | ||
issue.exact | ||
? `exactamente` | ||
: issue.inclusive | ||
? `menor o igual al` | ||
: `menor que el` | ||
} ${new Date(Number(issue.maximum))}`; | ||
else message = "Entrada inválida"; | ||
break; | ||
case ZodIssueCode.custom: | ||
message = `Entrada inválida`; | ||
break; | ||
case ZodIssueCode.invalid_intersection_types: | ||
message = `Valores de intersección no pudieron ser mezclados`; | ||
break; | ||
case ZodIssueCode.not_multiple_of: | ||
message = `Número debe ser múltiplo de ${issue.multipleOf}`; | ||
break; | ||
case ZodIssueCode.not_finite: | ||
message = "Número no puede ser infinito"; | ||
break; | ||
case ZodIssueCode.uniqueness: | ||
message = issue.duplicateElements?.length | ||
? `Elemento(s): '${issue.duplicateElements}' no son únicos` | ||
: "Los valores deben ser únicos"; | ||
break; | ||
case ZodIssueCode.invalid_file_type: | ||
message = `Tipo de archivo inválido. Se esperaba ${util.joinValues( | ||
issue.expected | ||
)}, se recibió '${issue.received}'`; | ||
break; | ||
case ZodIssueCode.invalid_file_name: | ||
message = `Nombre de archivo inválido`; | ||
break; | ||
default: | ||
message = _ctx.defaultError; | ||
util.assertNever(issue); | ||
} | ||
return { message }; | ||
}; | ||
|
||
export default errorMap; |
Oops, something went wrong.