Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(locales): add locale sl #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Locales implemented:
- `ro`
- `ru`
- `sk`
- `sl`
- `sv`
- `th`
- `tr`
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as pl from './locales/pl';
import * as pt from './locales/pt';
import * as ru from './locales/ru';
import * as sk from './locales/sk';
import * as sl from './locales/sl';
import * as th from './locales/th';
import * as tr from './locales/tr';
import * as uz from './locales/uz';
Expand Down Expand Up @@ -52,6 +53,7 @@ export {
ro,
ru,
sk,
sl,
th,
tr,
uz,
Expand Down
72 changes: 72 additions & 0 deletions src/locales/sl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*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 neveljaven.',
required: '${path} polje je obvezno',
defined: '${path} mora biti določeno',
notNull: '${path} ne sme biti null',
oneOf: '${path} mora biti ena od naslednjih vrednosti: ${values}',
notOneOf: '${path} ne sme biti ena od naslednjih vrednosti: ${values}',
notType: ({ path, type, value, originalValue }) => {
const isCast = originalValue != null && originalValue !== value;
let msg =
`${path} mora biti tip \`${type}\`, ` +
`toda končna vrednost je bila: \`${printValue(value, true)}\`` +
(isCast
? ` (pretvorjeno iz vrednosti \`${printValue(originalValue, true)}\`).`
: '.');

if (value === null) {
msg += `\n Če je "null" namenjena kot prazna vrednost se prepričaj da je shema označena kot` +
' `.nullable()`';
}

return msg;
},
};

export const string: LocaleObject['string'] = {
length: '${path} mora vsebovati točno dolžine ${length} znakov',
min: '${path} mora vsebovati vsaj ${min} znaki',
max: '${path} mora vsebovati največ ${max} znakov',
matches: '${path} se mora ujemati z naslednjim: "${regex}"',
email: '${path} mora biti veljaven e-naslov',
url: '${path} mora biti veljaven URL',
uuid: '${path} mora biti veljaven UUID',
trim: '${path} mora biti obrezan niz',
lowercase: '${path} mora biti niz malih črk',
uppercase: '${path} mora biti niz iz velikih črk',
};

export const number: LocaleObject['number'] = {
min: '${path} mora biti večji ali enak ${min}',
max: '${path} mora biti manjši ali enak ${max}',
lessThan: '${path} mora biti manjši kot ${less}',
moreThan: '${path} mora biti večji od ${more}',
positive: '${path} mora biti pozitivno število',
negative: '${path} mora biti negativno število',
integer: '${path} mora biti celo število',
};

export const date: LocaleObject['date'] = {
min: '${path} polje mora biti kasneje kot ${min}',
max: '${path} Polje mora biti prej kot ${max}',
};

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

export const object: LocaleObject['object'] = {
noUnknown:
'${path} polje nima veljavnih ključev: ${unknown}',
};

export const array: LocaleObject['array'] = {
min: '${path} polje mora vsebovati vsaj ${min} vrednosti',
max: '${path} polje mora vsebovati manj ali enako ${max} vrednosti',
length: '${path} mora vsebovati ${length} vrednosti',
};