Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
LoicMahieu committed Oct 31, 2023
2 parents 9fcb1e2 + 4822a68 commit faf9449
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 43 deletions.
2 changes: 2 additions & 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 All @@ -43,6 +44,7 @@ Locales implemented:
- `th`
- `ja`
- `zh-tw`
- `ko`

Please submit a PR with a new locale if you need it. In order to create a new locale, you could translate it automatically with `node scripts/create-locale` which will use google translate.

Expand Down
4 changes: 4 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 @@ -21,9 +22,11 @@ import * as zh from './locales/zh';
import * as zhtw from './locales/zhtw';
import * as th from './locales/th';
import * as ja from './locales/ja';
import * as ko from './locales/ko';

export {
ar,
bs,
da,
de,
es,
Expand All @@ -46,4 +49,5 @@ export {
th,
ja,
zhtw,
ko,
};
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',
};
66 changes: 66 additions & 0 deletions src/locales/ko.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { printValue, LocaleObject } from 'yup';

export const mixed: LocaleObject['mixed'] = {
default: '항목이 올바르지 않습니다.',
required: '항목은 필수입니다.',
defined: '항목 값이 정의되어야 합니다.',
notNull: '항목은 null일수 없습니다.',
oneOf: '항목은 다음 값중 하나여야 합니다: ${values}',

Check warning on line 8 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and ubuntu-latest

Unexpected template string expression

Check warning on line 8 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and windows-latest

Unexpected template string expression

Check warning on line 8 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and macOS-latest

Unexpected template string expression
notOneOf: '항목은 다음 값이 아니여야 합니다: ${values}',

Check warning on line 9 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and ubuntu-latest

Unexpected template string expression

Check warning on line 9 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and windows-latest

Unexpected template string expression

Check warning on line 9 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and macOS-latest

Unexpected template string expression
notType: ({ path, type, value, originalValue }) => {
const castMsg =
originalValue != null && originalValue !== value
? ` (\`${printValue(originalValue, true)}\` 값에서 캐스팅).`
: '.';

return type !== 'mixed'
? `${path} 항목은 \`${type}\` 타입이 필요한데, ` +
`최종 값은: \`${printValue(value, true)}\`` +
castMsg
: `${path} 항목은 구성된 타입과 일치해야 합니다. ` +
`검증 값은: \`${printValue(value, true)}\`` +
castMsg;
},
};

export const string: LocaleObject['string'] = {
length: '${path} 항목은 ${length} 글자여야 합니다.',

Check warning on line 27 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and ubuntu-latest

Unexpected template string expression

Check warning on line 27 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and windows-latest

Unexpected template string expression

Check warning on line 27 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and macOS-latest

Unexpected template string expression
min: '${path} 항목은 ${min} 글자이상이여야 합니다.',

Check warning on line 28 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and ubuntu-latest

Unexpected template string expression

Check warning on line 28 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and windows-latest

Unexpected template string expression

Check warning on line 28 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and macOS-latest

Unexpected template string expression
max: '${path} 항목은 ${max} 글자이하여야 합니다.',

Check warning on line 29 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and ubuntu-latest

Unexpected template string expression

Check warning on line 29 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and windows-latest

Unexpected template string expression

Check warning on line 29 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and macOS-latest

Unexpected template string expression
matches: '${path} 항목의 형식이 올바르지 않습니다: "${regex}"',

Check warning on line 30 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and ubuntu-latest

Unexpected template string expression

Check warning on line 30 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and windows-latest

Unexpected template string expression

Check warning on line 30 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and macOS-latest

Unexpected template string expression
email: '${path} 항목은 이메일형식이여야 합니다.',

Check warning on line 31 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and ubuntu-latest

Unexpected template string expression

Check warning on line 31 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and windows-latest

Unexpected template string expression

Check warning on line 31 in src/locales/ko.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 19.x and macOS-latest

Unexpected template string expression
url: '${path} 항목은 URL형식이여야 합니다.',
uuid: '${path} 항목은 UUID형식이여야 합니다.',
trim: '${path} 항목은 압뒤공백이 없어야 합니다',
lowercase: '${path} 항목은 소문자여야 합니다.',
uppercase: '${path} 항목은 대문자여야 합니다.',
};

export const number: LocaleObject['number'] = {
min: '${path} 항목은 ${min} 이상이여야 합니다.',
max: '${path} 항목은 ${max} 이하여야 합니다.',
lessThan: '${path} 항목은 ${less} 미만이여야 합니다.',
moreThan: '${path} 항목은 ${more} 초과여야 합니다.',
positive: '${path} 항목은 양수여야 합니다.',
negative: '${path} 항목은 음수여야 합니다.',
integer: '${path} 항목은 정수여야 합니다.',
};

export const date: LocaleObject['date'] = {
min: '${path} 항목은 ${min} 이후여야 합니다.',
max: '${path} 항목은 ${max} 이전이여야 합니다.',
};

export const boolean: LocaleObject['boolean'] = {
isValue: '${path} 항목은 ${value}여야 합니다.',
};

export const object: LocaleObject['object'] = {
noUnknown: '${path} 항목에 지정되지 않은 키가 있습니다: ${unknown}',
};

export const array: LocaleObject['array'] = {
min: '${path} 항목의 아이템은 ${min}개 이상이여야 합니다.',
max: '${path} 항목의 아이템은 ${max}개 이하여야 합니다.',
length: '${path} 항목의 아이템은 ${length}개여야 합니다.',
};
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 faf9449

Please sign in to comment.