Skip to content

Commit 0d1a8fe

Browse files
committed
update lang message
1 parent 118e632 commit 0d1a8fe

File tree

3 files changed

+135
-10
lines changed

3 files changed

+135
-10
lines changed

src/Locale/LocaleZhCN.php

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Inhere\Validate\Locale;
4+
5+
use Inhere\Validate\Validator\GlobalMessage;
6+
7+
/**
8+
* Class LocaleZhCN
9+
*
10+
* @package Inhere\Validate\Locale
11+
*/
12+
class LocaleZhCN
13+
{
14+
/**
15+
* Default error messages
16+
*
17+
* @var array
18+
*/
19+
public static $messages = [
20+
// 'int' 'integer'
21+
'integer' => [
22+
'{attr} 必须是整数!',
23+
'{attr} 必须是整数并且最小值是 {min}',
24+
'{attr} 必须是整数并且值的范围必须在 {min} ~ {max}',
25+
],
26+
// 'num'
27+
'number' => [
28+
'{attr} 必须是整数并且大于0!',
29+
'{attr} 必须是整数并且最小值是 {min}',
30+
'{attr} 必须是整数并且值的范围必须在 {min} ~ {max}',
31+
],
32+
// 'bool', 'boolean',
33+
'boolean' => '{attr} 必须是布尔类型!',
34+
'float' => '{attr} 必须是浮点数!',
35+
'url' => '{attr} is not a url address!',
36+
'email' => '{attr} is not a email address!',
37+
'date' => '{attr} is not a date format!',
38+
'dateFormat' => '{attr} is not in a {value0} date format!',
39+
'ip' => '{attr} is not IP address!',
40+
'ipv4' => '{attr} is not a IPv4 address!',
41+
'ipv6' => '{attr} is not a IPv6 address!',
42+
'required' => 'parameter {attr} is required!',
43+
'requiredIf' => 'parameter {attr} is required!',
44+
'length' => [
45+
'{attr} length validation is not through!',
46+
'{attr} must be an string/array and minimum length is {min}',
47+
'{attr} must be an string/array and length range {min} ~ {max}',
48+
],
49+
// 'range', 'between'
50+
'size' => [
51+
'{attr} size validation is not through!',
52+
'{attr} must be an integer/string/array and minimum value/length is {min}',
53+
// '{attr} must be an integer/string/array and value/length range {min} ~ {max}',
54+
'{attr} must be in the range {min} ~ {max}',
55+
],
56+
57+
// 'lengthEq', 'sizeEq'
58+
'fixedSize' => '{attr} length must is {value0}',
59+
60+
'eq' => '{attr} must be equals to {value0}',
61+
// 'different'
62+
'ne' => '{attr} can not be equals to {value0}',
63+
'min' => '{attr} minimum boundary is {value0}',
64+
'max' => '{attr} maximum boundary is {value0}',
65+
'lt' => '{attr} value must be less than {value0}',
66+
'lte' => '{attr} value must be less than or equals to {value0}',
67+
'gt' => '{attr} value must be greater than or equals to {value0}',
68+
'gte' => '{attr} value must be greater than or equals to {value0}',
69+
70+
// field compare
71+
'eqField' => '{attr} value must be less than {value0}',
72+
'neqField' => '{attr} value must be less than {value0}',
73+
'ltField' => '{attr} value must be less than {value0}',
74+
'lteField' => '{attr} value must be less than or equals to {value0}',
75+
'gtField' => '{attr} value must be greater than {value0}',
76+
'gteField' => '{attr} value must be greater than or equals to {value0}',
77+
78+
// 'in', 'enum',
79+
'enum' => '{attr} must in ({value0})',
80+
'notIn' => '{attr} cannot in ({value0})',
81+
82+
'string' => [
83+
'{attr} must be a string',
84+
'{attr} must be a string and minimum length be {min}',
85+
'{attr} must be a string and length range must be {min} ~ {max}',
86+
],
87+
88+
// 'regex', 'regexp',
89+
'regexp' => '{attr} does not match the {value0} conditions',
90+
91+
'mustBe' => '{attr} must be equals to {value0}',
92+
'notBe' => '{attr} can not be equals to {value0}',
93+
94+
'compare' => '{attr} must be equals to {value0}',
95+
'same' => '{attr} must be equals to {value0}',
96+
97+
'isArray' => '{attr} must be an array',
98+
'isMap' => '{attr} must be an array and is key-value format',
99+
'isList' => '{attr} must be an array of nature',
100+
'intList' => '{attr} must be an array and value is all integers',
101+
'numList' => '{attr} must be an array and value is all numbers',
102+
'strList' => '{attr} must be an array and value is all strings',
103+
'arrList' => '{attr} must be an array and value is all arrays',
104+
105+
'each' => '{attr} each value must be through the "{value0}" verify',
106+
'hasKey' => '{attr} must be contains the key {value0}',
107+
'distinct' => 'there should not be duplicate keys in the {attr}',
108+
109+
'json' => '{attr} must be an json string',
110+
111+
'file' => '{attr} must be an uploaded file',
112+
'image' => '{attr} must be an uploaded image file',
113+
114+
'callback' => '{attr} don\'t pass the test and verify!',
115+
'__default' => '{attr} validation is not through!',
116+
];
117+
118+
/**
119+
* register to global message
120+
*/
121+
public static function register(): void
122+
{
123+
GlobalMessage::setMessages(self::$messages);
124+
}
125+
}

src/Traits/ErrorMessageTrait.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,10 @@ public function setMessages(array $messages): self
299299
/**
300300
* 各个验证器的提示消息
301301
*
302-
* @param string|Closure $validator 验证器
303-
* @param string $field
304-
* @param array $args
305-
* @param string|array $message 自定义提示消息
302+
* @param string|Closure $validator 验证器
303+
* @param string $field
304+
* @param array $args
305+
* @param string|array|null $message 自定义提示消息
306306
*
307307
* @return string
308308
*/
@@ -316,7 +316,7 @@ public function getMessage($validator, string $field, array $args = [], $message
316316
// get message from built in dict.
317317
if (!$message) {
318318
$message = $this->findMessage($field, $rawName) ?: GlobalMessage::getDefault();
319-
// is array. It's defined multi error messages
319+
// is array. It's defined multi error messages
320320
} elseif (is_array($message)) {
321321
$message = $message[$rawName] ?? $this->findMessage($field, $rawName);
322322

@@ -366,7 +366,7 @@ protected function findMessage(string $field, string $rawName)
366366

367367
if (isset($this->_messages[$fullKey])) {
368368
$message = $this->_messages[$fullKey];
369-
// eg 'required' => 'some message ...'
369+
// eg 'required' => 'some message ...'
370370
} elseif (isset($this->_messages[$rawName])) {
371371
$message = $this->_messages[$rawName];
372372
} elseif (isset($this->_messages[$realName])) {

src/Validator/GlobalMessage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class GlobalMessage
1313
*
1414
* @var array
1515
*/
16-
private static $messages = [
16+
public static $messages = [
1717
// 'int' 'integer'
1818
'integer' => [
1919
'{attr} must be an integer!',
@@ -27,9 +27,9 @@ final class GlobalMessage
2727
'{attr} must be an integer and in the range {min} ~ {max}',
2828
],
2929
// 'bool', 'boolean',
30-
'boolean' => '{attr} must be is boolean!',
31-
'float' => '{attr} must be is float!',
32-
'url' => '{attr} is not a url address!',
30+
'boolean' => '{attr} must be an boolean!',
31+
'float' => '{attr} must be an float!',
32+
'url' => '{attr} must be a URL address!',
3333
'email' => '{attr} is not a email address!',
3434
'date' => '{attr} is not a date format!',
3535
'dateFormat' => '{attr} is not in a {value0} date format!',

0 commit comments

Comments
 (0)