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 lv (Latvian) #104

Open
wants to merge 3 commits 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 @@ -38,6 +38,7 @@ Locales implemented:
- `ja`
- `ko`
- `lt`
- `lv`
- `nb`
- `nl`
- `pl`
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import * as it from './locales/it';
import * as ja from './locales/ja';
import * as ko from './locales/ko';
import * as lt from './locales/lt';
import * as lv from './locales/lv';
import * as nb from './locales/nb';
import * as nl from './locales/nl';
import * as pl from './locales/pl';
Expand Down Expand Up @@ -45,6 +46,7 @@ export {
ja,
ko,
lt,
lv,
nb,
nl,
pl,
Expand Down
73 changes: 73 additions & 0 deletions src/locales/lv.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} nav derīgs',
required: '${path} ir nepieciešamais lauks',
defined: '${path} ir jādefinē',
notNull: '${path} nevar būt nulle',
oneOf: '${path} jābūt vienai no šīm vērtībām: ${values}',
notOneOf: '${path} nedrīkst būt vienai no šīm vērtībām: ${values}',
notType: ({ path, type, value, originalValue }) => {
const isCast = originalValue != null && originalValue !== value;
let msg =
`${path} jābūt \`${type}\` tipam, ` +
`bet galīgā vērtība bija: "${printValue(value, true)}\`` +
(isCast
? ` (lieta no vērtības \`${printValue(originalValue, true)}\`)`
: '');

if (value === null) {
msg +=
`\n Ja "nulle" ir paredzēts kā tukša vērtība, noteikti atzīmējiet shēmu kā` +
' `.nullable()`';
}

return msg;
},
};

export const string: LocaleObject['string'] = {
length: '${path} jābūt tieši ${length} rakstzīmēm',
min: '${path} jābūt vismaz ${min} rakstzīmēm',
max: '${path} jābūt ne vairāk kā ${max} rakstzīmēm',
matches: '${path} jāatbilst šādiem: "${regex}"',
email: '${path} jābūt derīgam e -pastam',
url: '${path} jābūt derīgam URL',
uuid: '${path} jābūt derīgam UUID',
trim: '${path} jābūt sagrieztai virknei',
lowercase: '${path} jābūt mazajam virknei',
uppercase: '${path} jābūt lielajam virknei',
};

export const number: LocaleObject['number'] = {
min: '${path} jābūt lielākam vai vienādam ar ${min}',
max: '${path} jābūt mazākam vai vienādam ar ${max}',
lessThan: '${path} jābūt mazākam par ${less}',
moreThan: '${path} jābūt lielākam par ${more}',
positive: '${path} jābūt pozitīvam skaitam',
negative: '${path} jābūt negatīvam skaitam',
integer: '${path} jābūt veselam skaitlim',
};

export const date: LocaleObject['date'] = {
min: '${path} laukam jābūt vēlāk nekā ${min}',
max: '${path} laukam jābūt agrāk par ${max}',
};

export const boolean: LocaleObject['boolean'] = {
isValue: '${path} laukam jābūt ${value}',
};

export const object: LocaleObject['object'] = {
noUnknown:
'${path} laukam nevar būt atslēgas, kas nav norādītas objekta formā',
};

export const array: LocaleObject['array'] = {
min: '${path} laukam jābūt vismaz ${min} priekšmetiem',
max: '${path} laukam jābūt mazākam vai vienādam ar ${max} priekšmetiem',
length: '${path} jābūt ${length} priekšmetiem',
};