@impelsys/validatorjs 3.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +27 -0
- package/CONTRIBUTE.md +34 -0
- package/LICENSE +20 -0
- package/README.md +607 -0
- package/dist/lang/ar.js +66 -0
- package/dist/lang/az.js +104 -0
- package/dist/lang/be.js +105 -0
- package/dist/lang/bg.js +105 -0
- package/dist/lang/bs.js +106 -0
- package/dist/lang/ca.js +40 -0
- package/dist/lang/cs.js +107 -0
- package/dist/lang/cy.js +106 -0
- package/dist/lang/da.js +51 -0
- package/dist/lang/de.js +46 -0
- package/dist/lang/el.js +43 -0
- package/dist/lang/en.js +54 -0
- package/dist/lang/es.js +40 -0
- package/dist/lang/et.js +106 -0
- package/dist/lang/eu.js +106 -0
- package/dist/lang/fa.js +42 -0
- package/dist/lang/fi.js +51 -0
- package/dist/lang/fr.js +40 -0
- package/dist/lang/hr.js +106 -0
- package/dist/lang/hu.js +106 -0
- package/dist/lang/id.js +51 -0
- package/dist/lang/it.js +41 -0
- package/dist/lang/ja.js +54 -0
- package/dist/lang/ka.js +106 -0
- package/dist/lang/ko.js +106 -0
- package/dist/lang/lt.js +106 -0
- package/dist/lang/lv.js +106 -0
- package/dist/lang/mk.js +106 -0
- package/dist/lang/mn.js +106 -0
- package/dist/lang/ms.js +106 -0
- package/dist/lang/nb_NO.js +42 -0
- package/dist/lang/nl.js +51 -0
- package/dist/lang/pl.js +42 -0
- package/dist/lang/pt.js +110 -0
- package/dist/lang/pt_BR.js +105 -0
- package/dist/lang/ro.js +51 -0
- package/dist/lang/ru.js +40 -0
- package/dist/lang/se.js +106 -0
- package/dist/lang/sl.js +106 -0
- package/dist/lang/sq.js +106 -0
- package/dist/lang/sr.js +106 -0
- package/dist/lang/sv.js +105 -0
- package/dist/lang/tr.js +51 -0
- package/dist/lang/ua.js +40 -0
- package/dist/lang/uk.js +106 -0
- package/dist/lang/vi.js +42 -0
- package/dist/lang/zh.js +42 -0
- package/dist/lang/zh_TW.js +42 -0
- package/dist/validator.js +2183 -0
- package/package.json +78 -0
- package/src/async.js +81 -0
- package/src/attributes.js +199 -0
- package/src/errors.js +77 -0
- package/src/lang/ar.js +63 -0
- package/src/lang/az.js +101 -0
- package/src/lang/be.js +102 -0
- package/src/lang/bg.js +102 -0
- package/src/lang/bs.js +103 -0
- package/src/lang/ca.js +37 -0
- package/src/lang/cs.js +104 -0
- package/src/lang/cy.js +103 -0
- package/src/lang/da.js +48 -0
- package/src/lang/de.js +43 -0
- package/src/lang/el.js +40 -0
- package/src/lang/en.js +51 -0
- package/src/lang/es.js +37 -0
- package/src/lang/et.js +103 -0
- package/src/lang/eu.js +103 -0
- package/src/lang/fa.js +39 -0
- package/src/lang/fi.js +48 -0
- package/src/lang/fr.js +37 -0
- package/src/lang/hr.js +103 -0
- package/src/lang/hu.js +103 -0
- package/src/lang/id.js +48 -0
- package/src/lang/it.js +38 -0
- package/src/lang/ja.js +51 -0
- package/src/lang/ka.js +103 -0
- package/src/lang/ko.js +103 -0
- package/src/lang/lt.js +103 -0
- package/src/lang/lv.js +103 -0
- package/src/lang/mk.js +103 -0
- package/src/lang/mn.js +103 -0
- package/src/lang/ms.js +103 -0
- package/src/lang/nb_NO.js +39 -0
- package/src/lang/nl.js +48 -0
- package/src/lang/pl.js +39 -0
- package/src/lang/pt.js +107 -0
- package/src/lang/pt_BR.js +102 -0
- package/src/lang/ro.js +48 -0
- package/src/lang/ru.js +37 -0
- package/src/lang/se.js +47 -0
- package/src/lang/sl.js +103 -0
- package/src/lang/sq.js +103 -0
- package/src/lang/sr.js +103 -0
- package/src/lang/sv.js +102 -0
- package/src/lang/tr.js +48 -0
- package/src/lang/ua.js +37 -0
- package/src/lang/uk.js +103 -0
- package/src/lang/vi.js +39 -0
- package/src/lang/zh.js +39 -0
- package/src/lang/zh_TW.js +39 -0
- package/src/lang.js +78 -0
- package/src/messages.js +152 -0
- package/src/rules.js +864 -0
- package/src/validator.js +662 -0
package/src/lang/tr.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
accepted: ':attribute kabul edilmeli.',
|
|
3
|
+
after: ':attribute alanı :after alanından sonra olmalıdır.',
|
|
4
|
+
after_or_equal: ':attribute alanı :after_or_equal alanına eşit veya sonra olmalıdır.',
|
|
5
|
+
alpha: ':attribute alanı sadece harflerden oluşabilir.',
|
|
6
|
+
alpha_dash: ':attribute alanı sadece alfa-nümerik, tire ve alt çizgi karakterlerden oluşabilir.',
|
|
7
|
+
alpha_num: ':attribute alanı alfa-nümerik olmalıdır.',
|
|
8
|
+
before: ':attribute alanı :before alanından önce olmalıdır.',
|
|
9
|
+
before_or_equal: ':attribute alanı :before_or_equal alanına eşit veya önce olmalıdır.',
|
|
10
|
+
between: ':attribute alanı :min ile :max arasında olabilir.',
|
|
11
|
+
confirmed: ':attribute uyuşmuyor.',
|
|
12
|
+
email: ':attribute formatı geçersiz.',
|
|
13
|
+
date: ':attribute geöerli bir tarih alanı değil.',
|
|
14
|
+
def: ':attribute hatalar içeriyor.',
|
|
15
|
+
digits: ':attribute sadece rakamlardan oluşabilir.',
|
|
16
|
+
digits_between: ':attribute :min ile :max arasında rakam olmalıdır.',
|
|
17
|
+
different: ':attribute ve :different farklı olmalı.',
|
|
18
|
+
in: 'Seçilen :attribute geçerli değil.',
|
|
19
|
+
integer: ':attribute tam sayı olmalı.',
|
|
20
|
+
hex: ':attribute onaltılık formatta olmalı.',
|
|
21
|
+
min: {
|
|
22
|
+
numeric: ':attribute en az :min olmalı.',
|
|
23
|
+
string: ':attribute en az :min karakter uzunluğunda olmalı.'
|
|
24
|
+
},
|
|
25
|
+
max: {
|
|
26
|
+
numeric: ':attribute en çok :max olabilir.',
|
|
27
|
+
string: ':attribute uzunluğu en çok :max karakter uzunluğunda olabilir.'
|
|
28
|
+
},
|
|
29
|
+
not_in: 'Seçilen :attribute geçerli değil.',
|
|
30
|
+
numeric: ':attribute sayı olmalı.',
|
|
31
|
+
present: ':attribute alanı bulunmalıdır (ancak boş olabilir).',
|
|
32
|
+
required: ':attribute alanı gerekli.',
|
|
33
|
+
required_if: ':attribute alanı :other alanı :value olduğunda gerekli.',
|
|
34
|
+
required_unless: ':attribute alanı :other alanı :value değilse gereklidir.',
|
|
35
|
+
required_with: ':attribute alanı :field boş değilse gereklidir.',
|
|
36
|
+
required_with_all: ':attribute alanı :fields alanları boş değilse gereklidir.',
|
|
37
|
+
required_without: ':attribute alanı :field alanı boşsa gereklidir.',
|
|
38
|
+
required_without_all: ':attribute alanı :fields alanları boşsa gereklidir.',
|
|
39
|
+
same: ':attribute ve :same aynı olmalı.',
|
|
40
|
+
size: {
|
|
41
|
+
numeric: ':attribute :size olmalı.',
|
|
42
|
+
string: ':attribute :size karakter uzunluğunda olmalı.'
|
|
43
|
+
},
|
|
44
|
+
string: ':attribute alfa-numerik olmalı.',
|
|
45
|
+
url: ':attribute formatı geçersiz.',
|
|
46
|
+
regex: ':attribute formatı geçersiz.',
|
|
47
|
+
attributes: {}
|
|
48
|
+
};
|
package/src/lang/ua.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
accepted: ':attribute повиннен бути прийнятий.',
|
|
3
|
+
alpha: 'Поле :attribute може складатись тільки з літер.',
|
|
4
|
+
alpha_dash: 'Поле :attribute може складатись тільки з літер, чисел, дефісів та символів підкреслення.',
|
|
5
|
+
alpha_num: 'Поле :attribute може складатись тільки з літер та чисел.',
|
|
6
|
+
between: 'Значення поля :attribute повинно знаходитись між :min і :max.',
|
|
7
|
+
confirmed: 'Поле :attribute не співпадає з підтвердженням.',
|
|
8
|
+
email: 'Значення поля :attribute повинно бути існуючою електронною адресою.',
|
|
9
|
+
def: 'Поле :attribute містить помилки.',
|
|
10
|
+
digits: 'Довжина числового поля :attribute повинна бути :digits.',
|
|
11
|
+
digits_between: 'Довжина цифрового поля :attribute повинна бути від :min до :max.',
|
|
12
|
+
different: 'Поля :attribute і :different повинні відрізнятись.',
|
|
13
|
+
in: 'Обране значення для :attribute помилкове.',
|
|
14
|
+
integer: 'Значення поля :attribute повинно бути цілим числом.',
|
|
15
|
+
hex: 'Значення поля :attribute повинно бути шістнадцяткового формату',
|
|
16
|
+
min: {
|
|
17
|
+
numeric: 'Значення поля :attribute повинно бути більшим або рівним :min.',
|
|
18
|
+
string: 'Кількість символів в полі :attribute повинна бути не менше :min.'
|
|
19
|
+
},
|
|
20
|
+
max: {
|
|
21
|
+
numeric: 'Значення поля :attribute повинно бути менше або рівне :max.',
|
|
22
|
+
string: 'Кількість символів в полі :attribute не може превищувати :max.'
|
|
23
|
+
},
|
|
24
|
+
not_in: 'Обране значення для :attribute помилкове.',
|
|
25
|
+
numeric: 'Значення поля :attribute повинно бути числом.',
|
|
26
|
+
present: 'Поле :attribute повинно бути присутнім (але може бути пустим).',
|
|
27
|
+
required: 'Поле :attribute обов\'язкове для заповнення.',
|
|
28
|
+
required_if: 'Поле :attribute потрібне у випадку коли значення поля :other рівне :value.',
|
|
29
|
+
same: 'Значеня поля :attribute повинно співпадати з :same.',
|
|
30
|
+
size: {
|
|
31
|
+
numeric: 'Значення поля :attribute повинно бути рівним :size.',
|
|
32
|
+
string: 'Кількість символів в полі :attribute повинна бути рівною :size.'
|
|
33
|
+
},
|
|
34
|
+
url: 'Поле :attribute повинне містити валідний URL.',
|
|
35
|
+
regex: 'Неправильний формат значення :attribute.',
|
|
36
|
+
attributes: {}
|
|
37
|
+
};
|
package/src/lang/uk.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
accepted: "Ви повинні прийняти :attribute.",
|
|
3
|
+
active_url: "Поле :attribute не є правильним URL.",
|
|
4
|
+
after: "Поле :attribute має містити дату не раніше :date.",
|
|
5
|
+
after_or_equal: "Поле :attribute має містити дату не раніше або дорівнюватися :date.",
|
|
6
|
+
alpha: "Поле :attribute має містити лише літери.",
|
|
7
|
+
alpha_dash: "Поле :attribute має містити лише літери, цифри та підкреслення.",
|
|
8
|
+
alpha_num: "Поле :attribute має містити лише літери та цифри.",
|
|
9
|
+
attributes: {},
|
|
10
|
+
array: "Поле :attribute має бути масивом.",
|
|
11
|
+
before: "Поле :attribute має містити дату не пізніше :date.",
|
|
12
|
+
before_or_equal: "Поле :attribute має містити дату не пізніше або дорівнюватися :date.",
|
|
13
|
+
between: {
|
|
14
|
+
numeric: "Поле :attribute має бути між :min та :max.",
|
|
15
|
+
file: "Розмір файлу в полі :attribute має бути не менше :min та не більше :max кілобайт.",
|
|
16
|
+
string: "Текст в полі :attribute має бути не менше :min та не більше :max символів.",
|
|
17
|
+
array: "Поле :attribute має містити від :min до :max елементів."
|
|
18
|
+
},
|
|
19
|
+
boolean: "Поле :attribute повинне містити логічний тип.",
|
|
20
|
+
confirmed: "Поле :attribute не збігається з підтвердженням.",
|
|
21
|
+
date: "Поле :attribute не є датою.",
|
|
22
|
+
date_format: "Поле :attribute не відповідає формату :format.",
|
|
23
|
+
different: "Поля :attribute та :other повинні бути різними.",
|
|
24
|
+
digits: "Довжина цифрового поля :attribute повинна дорівнювати :digits.",
|
|
25
|
+
digits_between: "Довжина цифрового поля :attribute повинна бути від :min до :max.",
|
|
26
|
+
dimensions: "Поле :attribute містіть неприпустимі розміри зображення.",
|
|
27
|
+
distinct: "Поле :attribute містить значення, яке дублюється.",
|
|
28
|
+
email: "Поле :attribute повинне містити коректну електронну адресу.",
|
|
29
|
+
file: "Поле :attribute має містити файл.",
|
|
30
|
+
filled: "Поле :attribute є обов'язковим для заповнення.",
|
|
31
|
+
exists: "Вибране для :attribute значення не коректне.",
|
|
32
|
+
gt: {
|
|
33
|
+
numeric: "The :attribute must be greater than :value.",
|
|
34
|
+
file: "The :attribute must be greater than :value kilobytes.",
|
|
35
|
+
string: "The :attribute must be greater than :value characters.",
|
|
36
|
+
array: "The :attribute must have more than :value items."
|
|
37
|
+
},
|
|
38
|
+
gte: {
|
|
39
|
+
numeric: "The :attribute must be greater than or equal :value.",
|
|
40
|
+
file: "The :attribute must be greater than or equal :value kilobytes.",
|
|
41
|
+
string: "The :attribute must be greater than or equal :value characters.",
|
|
42
|
+
array: "The :attribute must have :value items or more."
|
|
43
|
+
},
|
|
44
|
+
hex: "The :attribute field should have hexadecimal format",
|
|
45
|
+
image: "Поле :attribute має містити зображення.",
|
|
46
|
+
in: "Вибране для :attribute значення не коректне.",
|
|
47
|
+
in_array: "Значення поля :attribute не міститься в :other.",
|
|
48
|
+
integer: "Поле :attribute має містити ціле число.",
|
|
49
|
+
ip: "Поле :attribute має містити IP адресу.",
|
|
50
|
+
ipv4: "Поле :attribute має містити IPv4 адресу.",
|
|
51
|
+
ipv6: "Поле :attribute має містити IPv6 адресу.",
|
|
52
|
+
json: "Дані поля :attribute мають бути в форматі JSON.",
|
|
53
|
+
lt: {
|
|
54
|
+
numeric: "The :attribute must be less than :value.",
|
|
55
|
+
file: "The :attribute must be less than :value kilobytes.",
|
|
56
|
+
string: "The :attribute must be less than :value characters.",
|
|
57
|
+
array: "The :attribute must have less than :value items."
|
|
58
|
+
},
|
|
59
|
+
lte: {
|
|
60
|
+
numeric: "The :attribute must be less than or equal :value.",
|
|
61
|
+
file: "The :attribute must be less than or equal :value kilobytes.",
|
|
62
|
+
string: "The :attribute must be less than or equal :value characters.",
|
|
63
|
+
array: "The :attribute must not have more than :value items."
|
|
64
|
+
},
|
|
65
|
+
max: {
|
|
66
|
+
numeric: "Поле :attribute має бути не більше :max.",
|
|
67
|
+
file: "Файл в полі :attribute має бути не більше :max кілобайт.",
|
|
68
|
+
string: "Текст в полі :attribute повинен мати довжину не більшу за :max.",
|
|
69
|
+
array: "Поле :attribute повинне містити не більше :max елементів."
|
|
70
|
+
},
|
|
71
|
+
mimes: "Поле :attribute повинне містити файл одного з типів: :values.",
|
|
72
|
+
mimetypes: "Поле :attribute повинне містити файл одного з типів: :values.",
|
|
73
|
+
min: {
|
|
74
|
+
numeric: "Поле :attribute повинне бути не менше :min.",
|
|
75
|
+
file: "Розмір файлу в полі :attribute має бути не меншим :min кілобайт.",
|
|
76
|
+
string: "Текст в полі :attribute повинен містити не менше :min символів.",
|
|
77
|
+
array: "Поле :attribute повинне містити не менше :min елементів."
|
|
78
|
+
},
|
|
79
|
+
not_in: "Вибране для :attribute значення не коректне.",
|
|
80
|
+
not_regex: "The :attribute format is invalid.",
|
|
81
|
+
numeric: "Поле :attribute повинно містити число.",
|
|
82
|
+
present: "Поле :attribute повинне бути присутнє.",
|
|
83
|
+
regex: "Поле :attribute має хибний формат.",
|
|
84
|
+
required: "Поле :attribute є обов'язковим для заповнення.",
|
|
85
|
+
required_if: "Поле :attribute є обов'язковим для заповнення, коли :other є рівним :value.",
|
|
86
|
+
required_unless: "Поле :attribute є обов'язковим для заповнення, коли :other відрізняється від :values",
|
|
87
|
+
required_with: "Поле :attribute є обов'язковим для заповнення, коли :values вказано.",
|
|
88
|
+
required_with_all: "Поле :attribute є обов'язковим для заповнення, коли :values вказано.",
|
|
89
|
+
required_without: "Поле :attribute є обов'язковим для заповнення, коли :values не вказано.",
|
|
90
|
+
required_without_all: "Поле :attribute є обов'язковим для заповнення, коли :values не вказано.",
|
|
91
|
+
same: "Поля :attribute та :other мають співпадати.",
|
|
92
|
+
size: {
|
|
93
|
+
numeric: "Поле :attribute має бути довжини :size.",
|
|
94
|
+
file: "Файл в полі :attribute має бути розміром :size кілобайт.",
|
|
95
|
+
string: "Текст в полі :attribute повинен містити :size символів.",
|
|
96
|
+
array: "Поле :attribute повинне містити :size елементів."
|
|
97
|
+
},
|
|
98
|
+
string: "Поле :attribute повинне містити текст.",
|
|
99
|
+
timezone: "Поле :attribute повинне містити коректну часову зону.",
|
|
100
|
+
unique: "Таке значення поля :attribute вже існує.",
|
|
101
|
+
uploaded: "Завантаження поля :attribute не вдалося.",
|
|
102
|
+
url: "Формат поля :attribute неправильний."
|
|
103
|
+
};
|
package/src/lang/vi.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
accepted: ':attribute phải được chấp nhận.',
|
|
3
|
+
alpha: 'Trường :attribute phải là ký tự',
|
|
4
|
+
alpha_dash: ':attribute chỉ chấp nhận ký tự chữ cái, số, dấu gạch chéo và gạch dưới.',
|
|
5
|
+
alpha_num: ':attribute phải là ký tự chữ cái hoặc chữ số.',
|
|
6
|
+
between: ':attribute phải nằm trong khoảng :min và :max.',
|
|
7
|
+
confirmed: ':attribute xác nhận không trùng khớp.',
|
|
8
|
+
email: ':attribute không phải là email.',
|
|
9
|
+
date: ':attribute không phải là ngày hợp lệ',
|
|
10
|
+
def: 'Thuộc tính :attribute có lỗi.',
|
|
11
|
+
digits: ':attribute phải là số và có chiều dài bằng :digits.',
|
|
12
|
+
digits_between: 'Độ dài của trường :attribute phải nằm trong khoảng :min and :max chữ số.',
|
|
13
|
+
different: 'Giá trị của hai trường :attribute và :different phải khác nhau.',
|
|
14
|
+
in: 'Giá trị được chọn của :attribute không hợp lệ.',
|
|
15
|
+
integer: ':attribute phải là số nguyên.',
|
|
16
|
+
hex: 'The :attribute should have hexadecimal format',
|
|
17
|
+
min: {
|
|
18
|
+
numeric: ':attribute phải lớn hơn hoặc bằng :min.',
|
|
19
|
+
string: ':attribute phải có ít nhất :min ký tự.'
|
|
20
|
+
},
|
|
21
|
+
max: {
|
|
22
|
+
numeric: ':attribute phải nhỏ hơn hoặc bằng :max.',
|
|
23
|
+
string: ':attribute phải có ít hơn :max ký tự.'
|
|
24
|
+
},
|
|
25
|
+
not_in: 'Giá trị được chọn của trường :attribute không hợp lệ.',
|
|
26
|
+
numeric: ':attribute phải là số.',
|
|
27
|
+
present: 'Trường :attribute phải có mặt (nhưng có thể để trống).',
|
|
28
|
+
required: ':attribute bắt buộc nhập.',
|
|
29
|
+
required_if: ':attribute là bắt buộc khi :other có giá trị :value.',
|
|
30
|
+
same: 'Giá trị của :attribute và :same phải như nhau.',
|
|
31
|
+
size: {
|
|
32
|
+
numeric: ':attribute phải có chiều dài của bằng :size.',
|
|
33
|
+
string: 'Số ký tự của :attribute phải là :size ký tự.'
|
|
34
|
+
},
|
|
35
|
+
string: ':attribute không phải là một chuỗi',
|
|
36
|
+
url: ':attribute không phải là một Url hợp lệ.',
|
|
37
|
+
regex: ':attribute không đúng định dạng',
|
|
38
|
+
attributes: {}
|
|
39
|
+
};
|
package/src/lang/zh.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
accepted: ':attribute必须是可接受的.',
|
|
3
|
+
alpha: ':attribute只能包含字母.',
|
|
4
|
+
alpha_dash: ':attribute只能包含字母,连字符和下划线.',
|
|
5
|
+
alpha_num: ':attribute只能包含字母和数字.',
|
|
6
|
+
between: ':attribute的(大小,长度等)只能在:min和:max之间.',
|
|
7
|
+
confirmed: ':attribute确认不一致.',
|
|
8
|
+
email: ':attribute格式不正确.',
|
|
9
|
+
date: ':attribute日期格式错误.',
|
|
10
|
+
def: ':attribute属性错误.',
|
|
11
|
+
digits: ':attribute必须是:digits位小数.',
|
|
12
|
+
digits_between: ':attribute 必须是介于 :min 和 :max 位的数字。',
|
|
13
|
+
different: ':attribute和:different必须不同.',
|
|
14
|
+
in: '选择的:attribute无效',
|
|
15
|
+
integer: ':attribute必须是一个整数.',
|
|
16
|
+
hex: 'The :attribute should have hexadecimal format',
|
|
17
|
+
min: {
|
|
18
|
+
numeric: ':attribute不能小于:min.',
|
|
19
|
+
string: ':attribute长度不能小于:min.'
|
|
20
|
+
},
|
|
21
|
+
max: {
|
|
22
|
+
numeric: ':attribute不能大于:max.',
|
|
23
|
+
string: ':attribute长度不能大于:max.'
|
|
24
|
+
},
|
|
25
|
+
not_in: '所选的:attribute无效.',
|
|
26
|
+
numeric: ':attribute必须是一个数字.',
|
|
27
|
+
present: 'The :attribute field must be present (but can be empty).',
|
|
28
|
+
required: ':attribute不能为空.',
|
|
29
|
+
required_if: '当:other是:value时,:attribute不能为空.',
|
|
30
|
+
same: ':attribute和:same必须一致.',
|
|
31
|
+
size: {
|
|
32
|
+
numeric: ':attribute必须等于:size.',
|
|
33
|
+
string: ':attribute的长度必须等于:size.'
|
|
34
|
+
},
|
|
35
|
+
string: ':attribute必须是一个字符串.',
|
|
36
|
+
url: ':attribute格式不正确.',
|
|
37
|
+
regex: ':attribute格式不正确.',
|
|
38
|
+
attributes: {}
|
|
39
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
accepted: ':attribute必須接受。',
|
|
3
|
+
alpha: ':attribute只能包含字母。',
|
|
4
|
+
alpha_dash: ':attribute只能包含字母,連字符和下划線。',
|
|
5
|
+
alpha_num: ':attribute只能包含字母和數字。',
|
|
6
|
+
between: ':attribute的值只能在:min和:max之間。',
|
|
7
|
+
confirmed: ':attribute與確認輸入不一致。',
|
|
8
|
+
email: ':attribute的格式錯誤。',
|
|
9
|
+
date: ':attribute的日期格式錯誤。',
|
|
10
|
+
def: ':attribute屬性錯誤。',
|
|
11
|
+
digits: ':attribute必須是:digits位小數。',
|
|
12
|
+
digits_between: ':attribute 必須介於 :min 至 :max 位數字。',
|
|
13
|
+
different: ':attribute和:different必須不同。',
|
|
14
|
+
in: '選擇的:attribute無效',
|
|
15
|
+
integer: ':attribute必須是一個整數。',
|
|
16
|
+
hex: ':attribute 必須是十六進位格式',
|
|
17
|
+
min: {
|
|
18
|
+
numeric: ':attribute不能小於:min。',
|
|
19
|
+
string: ':attribute的長度不能小於:min.'
|
|
20
|
+
},
|
|
21
|
+
max: {
|
|
22
|
+
numeric: ':attribute不能大於:max。',
|
|
23
|
+
string: ':attribute的長度不能大於:max.'
|
|
24
|
+
},
|
|
25
|
+
not_in: '所選的:attribute無效。',
|
|
26
|
+
numeric: ':attribute必須是一個數字。',
|
|
27
|
+
present: ':attribute 一定要有值 (可以是空值)。',
|
|
28
|
+
required: ':attribute不能空白。',
|
|
29
|
+
required_if: '當:other是:value時,:attribute不能空白。',
|
|
30
|
+
same: ':attribute和:same必須一致。',
|
|
31
|
+
size: {
|
|
32
|
+
numeric: ':attribute必須等於:size。',
|
|
33
|
+
string: ':attribute的長度必須等於:size.'
|
|
34
|
+
},
|
|
35
|
+
string: ':attribute必須是一個字串。',
|
|
36
|
+
url: ':attribute格式不正確。',
|
|
37
|
+
regex: ':attribute格式不正確。',
|
|
38
|
+
attributes: {}
|
|
39
|
+
};
|
package/src/lang.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var Messages = require('./messages');
|
|
2
|
+
|
|
3
|
+
require('./lang/en');
|
|
4
|
+
|
|
5
|
+
var require_method = require;
|
|
6
|
+
|
|
7
|
+
var container = {
|
|
8
|
+
|
|
9
|
+
messages: {},
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Set messages for language
|
|
13
|
+
*
|
|
14
|
+
* @param {string} lang
|
|
15
|
+
* @param {object} rawMessages
|
|
16
|
+
* @return {void}
|
|
17
|
+
*/
|
|
18
|
+
_set: function(lang, rawMessages) {
|
|
19
|
+
this.messages[lang] = rawMessages;
|
|
20
|
+
},
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Set message for given language's rule.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} lang
|
|
26
|
+
* @param {string} attribute
|
|
27
|
+
* @param {string|object} message
|
|
28
|
+
* @return {void}
|
|
29
|
+
*/
|
|
30
|
+
_setRuleMessage: function(lang, attribute, message) {
|
|
31
|
+
this._load(lang);
|
|
32
|
+
if (message === undefined) {
|
|
33
|
+
message = this.messages[lang].def;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.messages[lang][attribute] = message;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Load messages (if not already loaded)
|
|
41
|
+
*
|
|
42
|
+
* @param {string} lang
|
|
43
|
+
* @return {void}
|
|
44
|
+
*/
|
|
45
|
+
_load: function(lang) {
|
|
46
|
+
if (!this.messages[lang]) {
|
|
47
|
+
try {
|
|
48
|
+
var rawMessages = require_method('./lang/' + lang);
|
|
49
|
+
this._set(lang, rawMessages);
|
|
50
|
+
} catch (e) {}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get raw messages for language
|
|
56
|
+
*
|
|
57
|
+
* @param {string} lang
|
|
58
|
+
* @return {object}
|
|
59
|
+
*/
|
|
60
|
+
_get: function(lang) {
|
|
61
|
+
this._load(lang);
|
|
62
|
+
return this.messages[lang];
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Make messages for given language
|
|
67
|
+
*
|
|
68
|
+
* @param {string} lang
|
|
69
|
+
* @return {Messages}
|
|
70
|
+
*/
|
|
71
|
+
_make: function(lang) {
|
|
72
|
+
this._load(lang);
|
|
73
|
+
return new Messages(lang, this.messages[lang]);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
module.exports = container;
|
package/src/messages.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
var Attributes = require('./attributes');
|
|
2
|
+
|
|
3
|
+
var Messages = function(lang, messages) {
|
|
4
|
+
this.lang = lang;
|
|
5
|
+
this.messages = messages;
|
|
6
|
+
this.customMessages = {};
|
|
7
|
+
this.attributeNames = {};
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
Messages.prototype = {
|
|
11
|
+
constructor: Messages,
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Set custom messages
|
|
15
|
+
*
|
|
16
|
+
* @param {object} customMessages
|
|
17
|
+
* @return {void}
|
|
18
|
+
*/
|
|
19
|
+
_setCustom: function(customMessages) {
|
|
20
|
+
this.customMessages = customMessages || {};
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Set custom attribute names.
|
|
25
|
+
*
|
|
26
|
+
* @param {object} attributes
|
|
27
|
+
*/
|
|
28
|
+
_setAttributeNames: function(attributes) {
|
|
29
|
+
this.attributeNames = attributes;
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Set the attribute formatter.
|
|
34
|
+
*
|
|
35
|
+
* @param {fuction} func
|
|
36
|
+
* @return {void}
|
|
37
|
+
*/
|
|
38
|
+
_setAttributeFormatter: function(func) {
|
|
39
|
+
this.attributeFormatter = func;
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get attribute name to display.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} attribute
|
|
46
|
+
* @return {string}
|
|
47
|
+
*/
|
|
48
|
+
_getAttributeName: function(attribute) {
|
|
49
|
+
var name = attribute;
|
|
50
|
+
if (this.attributeNames.hasOwnProperty(attribute)) {
|
|
51
|
+
return this.attributeNames[attribute];
|
|
52
|
+
} else if (this.messages.attributes.hasOwnProperty(attribute)) {
|
|
53
|
+
name = this.messages.attributes[attribute];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (this.attributeFormatter) {
|
|
57
|
+
name = this.attributeFormatter(name);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return name;
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Get all messages
|
|
65
|
+
*
|
|
66
|
+
* @return {object}
|
|
67
|
+
*/
|
|
68
|
+
all: function() {
|
|
69
|
+
return this.messages;
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Render message
|
|
74
|
+
*
|
|
75
|
+
* @param {Rule} rule
|
|
76
|
+
* @return {string}
|
|
77
|
+
*/
|
|
78
|
+
render: function(rule) {
|
|
79
|
+
if (rule.customMessage) {
|
|
80
|
+
return rule.customMessage;
|
|
81
|
+
}
|
|
82
|
+
var template = this._getTemplate(rule);
|
|
83
|
+
|
|
84
|
+
var message;
|
|
85
|
+
if (Attributes.replacements[rule.name]) {
|
|
86
|
+
message = Attributes.replacements[rule.name].apply(this, [template, rule]);
|
|
87
|
+
} else {
|
|
88
|
+
message = this._replacePlaceholders(rule, template, {});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return message;
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get the template to use for given rule
|
|
96
|
+
*
|
|
97
|
+
* @param {Rule} rule
|
|
98
|
+
* @return {string}
|
|
99
|
+
*/
|
|
100
|
+
_getTemplate: function(rule) {
|
|
101
|
+
|
|
102
|
+
var messages = this.messages;
|
|
103
|
+
var template = messages.def;
|
|
104
|
+
var customMessages = this.customMessages;
|
|
105
|
+
var formats = [rule.name + '.' + rule.attribute, rule.name];
|
|
106
|
+
|
|
107
|
+
for (var i = 0, format; i < formats.length; i++) {
|
|
108
|
+
format = formats[i];
|
|
109
|
+
if (customMessages.hasOwnProperty(format)) {
|
|
110
|
+
template = customMessages[format];
|
|
111
|
+
break;
|
|
112
|
+
} else if (messages.hasOwnProperty(format)) {
|
|
113
|
+
template = messages[format];
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (typeof template === 'object') {
|
|
119
|
+
template = template[rule._getValueType()];
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return template;
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Replace placeholders in the template using the data object
|
|
127
|
+
*
|
|
128
|
+
* @param {Rule} rule
|
|
129
|
+
* @param {string} template
|
|
130
|
+
* @param {object} data
|
|
131
|
+
* @return {string}
|
|
132
|
+
*/
|
|
133
|
+
_replacePlaceholders: function(rule, template, data) {
|
|
134
|
+
var message, attribute;
|
|
135
|
+
|
|
136
|
+
data.attribute = this._getAttributeName(rule.attribute);
|
|
137
|
+
data[rule.name] = data[rule.name] || rule.getParameters().join(',');
|
|
138
|
+
|
|
139
|
+
if (typeof template === 'string' && typeof data === 'object') {
|
|
140
|
+
message = template;
|
|
141
|
+
|
|
142
|
+
for (attribute in data) {
|
|
143
|
+
message = message.replace(new RegExp(':' + attribute, 'g'), data[attribute]);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return message;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
module.exports = Messages;
|