Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cfdbc23

Browse files
Support multi lang .
1 parent 1bcc469 commit cfdbc23

File tree

11 files changed

+64
-22
lines changed

11 files changed

+64
-22
lines changed

‎resources/lang/en/validation.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/laravel-validation
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
return [
10+
'id' => ':attribute must be an id number of Vietnam.',
11+
'mobile' => ':attribute must be a mobile phone number of Vietnam.',
12+
'land_line' => ':attribute must be a land line phone number of Vietnam.',
13+
'ip' => [
14+
'v4' => ':attribute must be Vietnam ipv4.',
15+
'v6' => ':attribute must be Vietnam ipv6.',
16+
'default' => ':attribute must be Vietnam ip.'
17+
]
18+
];

‎resources/lang/vi/validation.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* @link https://github.com/phpviet/laravel-validation
4+
*
5+
* @copyright (c) PHP Viet
6+
* @license [MIT](https://opensource.org/licenses/MIT)
7+
*/
8+
9+
return [
10+
'id' => ':attribute phải là số chứng minh thư hoặc thẻ căn cước tại Việt Nam.',
11+
'mobile' => ':attribute phải là số di động tại Việt Nam.',
12+
'land_line' => ':attribute phải là số điện thoại bàn tại Việt Nam.',
13+
'ip' => [
14+
'v4' => ':attribute phải là ipv4 tại Việt Nam.',
15+
'v6' => ':attribute phải là ipv6 tại Việt Nam.',
16+
'default' => ':attribute phải là ip Việt Nam.'
17+
]
18+
];

‎src/Rules/IdVN.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public function passes($attribute, $value): bool
2929
*/
3030
public function message(): string
3131
{
32-
return __('validation.phpviet.id');
32+
return __('phpVietValidation::validation.id');
3333
}
3434
}

‎src/Rules/IpVN.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ public function message(): string
5252
switch ($this->version) {
5353
case self::IPV4:
5454

55-
return __('validation.phpviet.ipv4');
55+
return __('phpVietValidation::validation.ip.v4');
5656
case self::IPV6:
5757

58-
return __('validation.phpviet.ipv6');
58+
return __('phpVietValidation::validation.ip.v6');
5959
default:
6060

61-
return __('validation.phpviet.ip');
61+
return __('phpVietValidation::validation.ip.default');
6262

6363
}
6464
}

‎src/Rules/LandLineVN.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public function passes($attribute, $value): bool
2929
*/
3030
public function message(): string
3131
{
32-
return __('validation.phpviet.land_line');
32+
return __('phpVietValidation::validation.land_line');
3333
}
3434
}

‎src/Rules/MobileVN.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public function passes($attribute, $value): bool
2929
*/
3030
public function message(): string
3131
{
32-
return __('validation.phpviet.mobile');
32+
return __('phpVietValidation::validation.mobile');
3333
}
3434
}

‎src/ServiceProvider.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@
2121
class ServiceProvider extends BaseServiceProvider
2222
{
2323
public function boot(): void
24+
{
25+
$this->loadTrans();
26+
$this->loadExt();
27+
}
28+
29+
protected function loadTrans(): void
30+
{
31+
$this->publishes([
32+
__DIR__ . '/../resources/lang' => resource_path('lang/vendor/phpVietValidation'),
33+
]);
34+
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang/', 'phpVietValidation');
35+
}
36+
37+
protected function loadExt(): void
2438
{
2539
if (isset($this->app['validator'])) {
2640
foreach ($this->getCallableRules() as $name => $rule) {

‎tests/IdVNTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ public function testInvalidIp()
4848

4949
public function testCanTranslateErrorMessage()
5050
{
51-
Lang::addLines([
52-
'validation.phpviet.id' => 'id',
53-
], Lang::getLocale());
51+
Lang::setLocale('vi');
5452
$rule = new IdVN();
5553
$rule->passes('attribute', '025479661123123123123!!!');
56-
$this->assertEquals('id', $rule->message());
54+
$this->assertEquals(':attribute phải là số chứng minh thư hoặc thẻ căn cước tại Việt Nam.', $rule->message());
5755
}
5856
}

‎tests/IpVNTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ public function testInvalidCases()
6161

6262
public function testCanTranslateErrorMessage()
6363
{
64-
Lang::addLines([
65-
'validation.phpviet.ip' => 'ip',
66-
], Lang::getLocale());
64+
Lang::setLocale('vi');
6765
$rule = new IpVN();
6866
$rule->passes('attribute', '113.173.134.203@');
69-
$this->assertEquals('ip', $rule->message());
67+
$this->assertEquals(':attribute phải là ip Việt Nam.', $rule->message());
7068
}
7169
}

‎tests/LandLineVNTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,9 @@ public function testInvalidIp()
4848

4949
public function testCanTranslateErrorMessage()
5050
{
51-
Lang::addLines([
52-
'validation.phpviet.land_line' => 'land_line',
53-
], Lang::getLocale());
51+
Lang::setLocale('vi');
5452
$rule = new LandLineVN();
5553
$rule->passes('attribute', '02838574955!!!');
56-
$this->assertEquals('land_line', $rule->message());
54+
$this->assertEquals(':attribute phải là số điện thoại bàn tại Việt Nam.', $rule->message());
5755
}
5856
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /