Skip to content

Commit

Permalink
Merge branch 'LoicMahieu:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MinByeongDon authored Nov 1, 2023
2 parents ee9fa2e + faf9449 commit 83d608e
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 43 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ setLocale(fr);
Locales implemented:

- `ar`
- `bs`
- `da`
- `de`
- `es`
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ar from './locales/ar';
import * as bs from './locales/bs';
import * as da from './locales/da';
import * as de from './locales/de';
import * as es from './locales/es';
Expand All @@ -25,6 +26,7 @@ import * as ko from './locales/ko';

export {
ar,
bs,
da,
de,
es,
Expand Down
73 changes: 73 additions & 0 deletions src/locales/bs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*eslint-disable no-template-curly-in-string*/

import { printValue, LocaleObject } from 'yup';

// Based on https://github.com/jquense/yup/blob/b940eef48eb7456622ae384d0ffa7363d4fbad25/src/locale.ts
export const mixed: LocaleObject['mixed'] = {
default: '${path} je nevažeći.',
required: '${path} je obavezno polje',
defined: '${path} mora biti definisan',
notNull: '${path} ne može biti null',
oneOf: '${path} mora biti jedna od sljedećih vrijednosti: ${values}',
notOneOf: '${path} ne smije biti jedna od sljedećih vrijednosti: ${values}',
notType: ({ path, type, value, originalValue }) => {
const isCast = originalValue != null && originalValue !== value;
let msg =
`${path} mora biti tipa \`${type}\`` +
` ali konačna vrijednost bila je: \`${printValue(value, true)}\`` +
(isCast
? ` (pretvoreno iz vrijednosti \`${printValue(originalValue, true)}\`).`
: '.');

if (value === null) {
msg +=
`\nAko je "null" namijenjen kao prazna vrijednost, obavezno označite shemu kao` +
' `.nullable()`';
}

return msg;
},
};

export const string: LocaleObject['string'] = {
length: '${path} mora imati tačno ${length} karaktera',
min: '${path} mora imati najmanje ${min} karaktera',
max: '${path} mora imati najviše ${max} karaktera',
matches: '${path} mora odgovarati sljedećem: "${regex}"',
email: '${path} mora biti važeća email adresa',
url: '${path} mora biti važeći URL',
uuid: '${path} mora biti važeći UUID',
trim: '${path} mora biti obrezan niz znakova',
lowercase: '${path} mora biti niz znakova malim slovima',
uppercase: '${path} mora biti niz znakova velikim slovima',
};

export const number: LocaleObject['number'] = {
min: '${path} mora biti veći ili jednak ${min}',
max: '${path} mora biti manji ili jednak ${max}',
lessThan: '${path} mora biti manje od ${less}',
moreThan: '${path} mora biti veće od ${more}',
positive: '${path} mora biti pozitivan broj',
negative: '${path} mora biti negativan broj',
integer: '${path} mora biti cijeli broj',
};

export const date: LocaleObject['date'] = {
min: '${path} polje mora biti kasnije od ${min}',
max: '${path} polje mora biti ranije od ${max}',
};

export const boolean: LocaleObject['boolean'] = {
isValue: '${path} polje mora biti ${value}',
};

export const object: LocaleObject['object'] = {
noUnknown:
'${path} polje ne smije imati ključeve koji nisu navedeni u obliku objekta',
};

export const array: LocaleObject['array'] = {
min: '${path} polje mora imati najmanje ${min} stavki',
max: '${path} polje mora imati najviše ${max} stavki',
length: '${path} mora imati ${length} stavki',
};
32 changes: 16 additions & 16 deletions src/locales/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export const mixed: LocaleObject['mixed'] = {
required: '${path} is een vereist veld',
defined: '${path} moet worden gedefinieerd',
notNull: '${path} kan niet leeg zijn',
oneOf: '${path} Moet een van de volgende waarden zijn: ${values}',
oneOf: '${path} moet een van de volgende waarden zijn: ${values}',
notOneOf: '${path} mag niet een van de volgende waarden zijn: ${values}',
notType: ({ path, type, value, originalValue }) => {
const isCast = originalValue != null && originalValue !== value;
let msg =
`${path} moet een \`${type}\` type zijn, ` +
`Maar de uiteindelijke waarde was: \`${printValue(value, true)}\`` +
`maar de uiteindelijke waarde was: \`${printValue(value, true)}\`` +
(isCast
? ` (gegoten uit de waarde \`${printValue(originalValue, true)}\`).`
: '.');
Expand All @@ -33,41 +33,41 @@ export const string: LocaleObject['string'] = {
length: '${path} moet precies ${length} tekens zijn',
min: '${path} moet op zijn minst ${min} tekens zijn',
max: '${path} moet maximaal ${max} tekens zijn',
matches: '${path} moet het volgende overeenkomen: "${regex}"',
email: '${path} Moet een geldige e -mail zijn',
url: '${path} Moet een geldige URL zijn',
uuid: '${path} Moet een geldige uuid zijn',
trim: '${path} Moet een getrimde string zijn',
lowercase: '${path} Moet een kleine letters zijn',
uppercase: '${path} Moet een hoofdstreek zijn',
matches: '${path} moet overeenkomen met: "${regex}"',
email: '${path} moet een geldige e-mail zijn',
url: '${path} moet een geldige URL zijn',
uuid: '${path} moet een geldige uuid zijn',
trim: '${path} mag geen begin- of eindspaties bevatten',
lowercase: '${path} mag alleen bestaan uit kleine letters',
uppercase: '${path} mag alleen bestaan uit hoofdletters',
};

export const number: LocaleObject['number'] = {
min: '${path} moet groter zijn dan of gelijk zijn aan ${min}',
max: '${path} moet kleiner zijn dan of gelijk zijn aan ${max}',
lessThan: '${path} moet minder zijn dan ${less}',
moreThan: '${path} moet groter zijn dan ${more}',
positive: '${path} Moet een positief getal zijn',
positive: '${path} moet een positief getal zijn',
negative: '${path} moet een negatief getal zijn',
integer: '${path} moet een geheel getal zijn',
};

export const date: LocaleObject['date'] = {
min: '${path} Veld moet later zijn dan ${min}',
max: '${path} Veld moet eerder zijn dan ${max}',
min: '${path} veld moet later zijn dan ${min}',
max: '${path} veld moet eerder zijn dan ${max}',
};

export const boolean: LocaleObject['boolean'] = {
isValue: '${path} Veld moet ${value} zijn',
isValue: '${path} veld moet ${value} zijn',
};

export const object: LocaleObject['object'] = {
noUnknown:
'${path} Veld kan geen sleutels hebben die niet in de objectvorm zijn opgegeven',
'${path} mag geen waarden bevatten die niet zijn opgegeven in het object',
};

export const array: LocaleObject['array'] = {
min: '${path} Veld moet ten minste ${min} items hebben',
max: '${path} Veld moet minder dan of gelijk hebben aan ${max} items',
min: '${path} veld moet ten minste ${min} items bevatten',
max: '${path} veld mag niet meer dan ${max} items bevatten',
length: '${path} moet ${length} items hebben',
};
64 changes: 37 additions & 27 deletions src/locales/pt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,49 @@ import { printValue, LocaleObject } from 'yup';
// Based on https://github.com/jquense/yup/blob/b940eef48eb7456622ae384d0ffa7363d4fbad25/src/locale.ts
export const mixed: LocaleObject['mixed'] = {
default: '${path} é inválido.',
required: '${path} é um campo necessário',
defined: '${path} deve ser definido',
notNull: '${path} não pode ser nulo',
oneOf: '${path} deve ser um dos seguintes valores: ${values}',
notOneOf: '${path} não deve ser um dos seguintes valores: ${values}',
required: '${path} é obrigatório',
defined: '${path} não deve ser indefinido',
notNull: '${path} não pode ser vazio',
oneOf: '${path} deve ter um dos seguintes valores: ${values}',
notOneOf: '${path} não deve ter nenhum dos seguintes valores: ${values}',
notType: ({ path, type, value, originalValue }) => {
const isCast = originalValue != null && originalValue !== value;
let msg =
`${path} deve ser um \`${type}, ` +
`Mas o valor final foi: \`${printValue(value, true)}\`` +
`${path} deve ser do tipo \`${type}\`, ` +
`mas o valor final foi: \`${printValue(value, true)}\`` +
(isCast
? ` (lançado do valor \`${printValue(originalValue, true)}\`).`
? ` (cast do valor \`${printValue(originalValue, true)}\`).`
: '.');

if (value === null) {
msg +=
`\n Se "nulo" for destinado a um valor vazio, marque o esquema como` +
' `.nullable()`';
'\n Se a intenção era usar "null" como um valor em branco marque o esquema como `.nullable()`';
}

return msg;
},
};

export const string: LocaleObject['string'] = {
length: '${path} deve ser exatamente ${length} caracteres',
min: '${path} deve ser pelo menos ${min} caracteres',
max: '${path} deve ser no máximo ${max} caracteres',
matches: '${path} deve corresponder ao seguinte: "${regex}"',
email: '${path} deve ser um e -mail válido',
url: '${path} deve ser um URL válido',
length: ({ path, length }) =>
`${path} deve ter exatamente ${length} ${
length === 1 ? 'caractere' : 'caracteres'
}`,
min: ({ path, min }) =>
`${path} deve ter no mínimo ${min} ${
min === 1 ? 'caractere' : 'caracteres'
}`,
max: ({ path, max }) =>
`${path} deve ter no máximo ${max} ${
max === 1 ? 'caractere' : 'caracteres'
}`,
matches: '${path} deve corresponder ao padrão: "${regex}"',
email: '${path} deve ser um e-mail válido',
url: '${path} deve ser uma URL válida',
uuid: '${path} deve ser um UUID válido',
trim: '${path} deve ser uma corda aparada',
lowercase: '${path} deve ser uma corda minúscula',
uppercase: '${path} deve ser uma corda de caixa superior',
trim: '${path} não deve conter espaços no início nem no fim',
lowercase: '${path} deve estar em letras minúsculas',
uppercase: '${path} deve estar em letras maiúsculas',
};

export const number: LocaleObject['number'] = {
Expand All @@ -53,21 +61,23 @@ export const number: LocaleObject['number'] = {
};

export const date: LocaleObject['date'] = {
min: '${path} O campo deve ser posterior a ${min}',
max: '${path} O campo deve ser mais cedo que ${max}',
min: '${path} deve ser posterior a ${min}',
max: '${path} deve ser anterior a ${max}',
};

export const boolean: LocaleObject['boolean'] = {
isValue: '${path} O campo deve ser ${value}',
isValue: '${path} deve ser ${value}',
};

export const object: LocaleObject['object'] = {
noUnknown:
'${path} O campo não pode ter chaves não especificadas na forma do objeto',
noUnknown: '${path} tem chaves desconhecidas: ${unknown}',
};

export const array: LocaleObject['array'] = {
min: '${path} O campo deve ter pelo menos ${min} itens',
max: '${path} O campo deve ter menos ou igual a ${max} itens',
length: '${path} deve ter ${length} itens',
min: ({ path, min }) =>
`${path} deve ter no mínimo ${min} ${min === 1 ? 'item' : 'itens'}`,
max: ({ path, max }) =>
`${path} deve ter no máximo ${max} ${max === 1 ? 'item' : 'itens'}`,
length: ({ path, length }) =>
`${path} deve ter ${length} ${length === 1 ? 'item' : 'itens'}`,
};

0 comments on commit 83d608e

Please sign in to comment.