Skip to content

Commit fd50b13

Browse files
committed
Add translation support
1 parent b23223e commit fd50b13

13 files changed

+85
-37
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
composer.lock
33
/vendor/
4+
*.cache

Diff for: composer.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
],
1212
"require": {
1313
"php": ">=7.1",
14-
"illuminate/contracts": "^5.1",
15-
"divineomega/laravel-password-exposed-validation-rule": "^2.0.1",
16-
"illuminate/support": "^5.1"
14+
"laravel/framework": "^5.1",
15+
"divineomega/laravel-password-exposed-validation-rule": "^2.0.1"
1716
},
1817
"require-dev": {
19-
"phpunit/phpunit": "^5.7",
2018
"fzaninotto/faker": "^1.6",
21-
"php-coveralls/php-coveralls": "^2.0"
19+
"php-coveralls/php-coveralls": "^2.0",
20+
"orchestra/testbench": "^3.1"
2221
},
2322
"autoload": {
2423
"psr-4": {

Diff for: resources/lang/en/validation.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
return [
4+
'can-not-contain-word' => 'The :attribute can not contain the word \':word\'.',
5+
'can-not-be-similar-to-word' => 'The :attribute can not be similar to the word \':word\'.',
6+
'found-in-data-breach' => 'The :attribute was found in a third party data breach, and can not be used.',
7+
'can-not-be-dictionary-word' => 'The :attribute can not be a dictionary word.',
8+
];

Diff for: src/Rules/BreachedPasswords.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public function __construct(PasswordExposedChecker $passwordExposedChecker = nul
2323
{
2424
parent::__construct($passwordExposedChecker);
2525

26-
$this->setMessage(
27-
'The :attribute was found in a third party data breach, and can not be used.'
28-
);
26+
$this->setMessage(__('laravel-nist-password-rules::validation.found-in-data-breach'));
2927
}
3028
}

Diff for: src/Rules/ContextSpecificWords.php

+8-12
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,13 @@ class ContextSpecificWords implements Rule
2121
public function __construct($username)
2222
{
2323
$text = '';
24-
// @codeCoverageIgnoreStart
25-
if (function_exists('config')) {
26-
$text = config('app.name');
27-
$text .= ' ';
28-
$text .= str_replace(
29-
['http://', 'https://', '-', '_', '.com', '.org', '.biz', '.net', '.'],
30-
' ',
31-
config('app.url'));
32-
$text .= ' ';
33-
}
34-
// @codeCoverageIgnoreEnd
24+
$text = config('app.name');
25+
$text .= ' ';
26+
$text .= str_replace(
27+
['http://', 'https://', '-', '_', '.com', '.org', '.biz', '.net', '.'],
28+
' ',
29+
config('app.url'));
30+
$text .= ' ';
3531
$text .= $username;
3632

3733
$words = explode(' ', strtolower($text));
@@ -75,6 +71,6 @@ public function passes($attribute, $value)
7571
*/
7672
public function message()
7773
{
78-
return 'The :attribute can not contain the word \''.$this->detectedWord.'\'.';
74+
return __('laravel-nist-password-rules::validation.can-not-contain-word', ['word' => $this->detectedWord]);
7975
}
8076
}

Diff for: src/Rules/DerivativesOfContextSpecificWords.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public function passes($attribute, $value)
5656
*/
5757
public function message()
5858
{
59-
return 'The :attribute can not be similar to the word \''.$this->detectedWord.'\'.';
59+
return __('laravel-nist-password-rules::validation.can-not-be-similar-to-word', ['word' => $this->detectedWord]);
6060
}
6161
}

Diff for: src/Rules/DictionaryWords.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ public function passes($attribute, $value)
4444
*/
4545
public function message()
4646
{
47-
return 'The :attribute can not be a dictionary word.';
47+
return __('laravel-nist-password-rules::validation.can-not-be-dictionary-word');
4848
}
4949
}

Diff for: src/ServiceProvider.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace LangleyFoxall\LaravelNISTPasswordRules;
4+
5+
use Illuminate\Support\Facades\Lang;
6+
7+
class ServiceProvider extends \Illuminate\Support\ServiceProvider
8+
{
9+
/**
10+
* Bootstrap any application services.
11+
*
12+
* @return void
13+
*/
14+
public function boot()
15+
{
16+
$this->loadTranslationsFrom(__DIR__.'/../resources/lang', 'laravel-nist-password-rules');
17+
18+
$this->publishes([
19+
__DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-nist-password-rules'),
20+
]);
21+
}
22+
23+
/**
24+
* Register bindings in the container.
25+
*
26+
* @return void
27+
*/
28+
public function register()
29+
{
30+
31+
}
32+
}

Diff for: tests/Unit/BreachedPasswordsTest.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
use Faker\Factory;
66
use LangleyFoxall\LaravelNISTPasswordRules\Rules\BreachedPasswords;
7-
use PHPUnit\Framework\TestCase;
7+
use LangleyFoxall\LaravelNISTPasswordRules\ServiceProvider;
8+
use Orchestra\Testbench\TestCase;
89

910
class BreachedPasswordsTest extends TestCase
1011
{
12+
protected function getPackageProviders($app)
13+
{
14+
return [ServiceProvider::class];
15+
}
16+
1117
public function exposedPasswordsProvider()
1218
{
1319
return [

Diff for: tests/Unit/ContextSpecificWordsTest.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@
44

55
use Faker\Factory;
66
use LangleyFoxall\LaravelNISTPasswordRules\Rules\ContextSpecificWords;
7-
use PHPUnit\Framework\TestCase;
7+
use LangleyFoxall\LaravelNISTPasswordRules\ServiceProvider;
8+
use Orchestra\Testbench\TestCase;
89

910
class ContextSpecificWordsTest extends TestCase
1011
{
1112
private static $username;
1213

13-
public function __construct(?string $name = null, array $data = [], string $dataName = '')
14+
protected function getPackageProviders($app)
1415
{
15-
parent::__construct($name, $data, $dataName);
16+
return [ServiceProvider::class];
17+
}
1618

19+
public function contextSpecificWordsProvider()
20+
{
1721
if (!self::$username) {
1822
$faker = Factory::create();
1923
self::$username = $faker->userName;
2024
}
21-
}
2225

23-
public function contextSpecificWordsProvider()
24-
{
2526
return [
2627
[self::$username],
2728
[strtoupper(self::$username)],

Diff for: tests/Unit/DerivativesOfContextSpecificWordsTest.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,25 @@
44

55
use Faker\Factory;
66
use LangleyFoxall\LaravelNISTPasswordRules\Rules\DerivativesOfContextSpecificWords;
7-
use PHPUnit\Framework\TestCase;
7+
use LangleyFoxall\LaravelNISTPasswordRules\ServiceProvider;
8+
use Orchestra\Testbench\TestCase;
89

910
class DerivativesOfContextSpecificWordsTest extends TestCase
1011
{
1112
private static $username;
1213

13-
public function __construct(?string $name = null, array $data = [], string $dataName = '')
14+
protected function getPackageProviders($app)
1415
{
15-
parent::__construct($name, $data, $dataName);
16+
return [ServiceProvider::class];
17+
}
1618

19+
public function contextSpecificWordsProvider()
20+
{
1721
if (!self::$username) {
1822
$faker = Factory::create();
1923
self::$username = $faker->userName;
2024
}
21-
}
2225

23-
public function contextSpecificWordsProvider()
24-
{
2526
return [
2627
[self::$username],
2728
[strtoupper(self::$username)],

Diff for: tests/Unit/DictionaryWordsTest.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
namespace LangleyFoxall\LaravelNISTPasswordRules\Tests\Unit;
44

55
use LangleyFoxall\LaravelNISTPasswordRules\Rules\DictionaryWords;
6-
use PHPUnit\Framework\TestCase;
6+
use LangleyFoxall\LaravelNISTPasswordRules\ServiceProvider;
7+
use Orchestra\Testbench\TestCase;
78

89
class DictionaryWordsTest extends TestCase
910
{
11+
protected function getPackageProviders($app)
12+
{
13+
return [ServiceProvider::class];
14+
}
15+
1016
public function dictionaryWordsProvider()
1117
{
1218
return [

Diff for: tests/Unit/PasswordRulesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use Illuminate\Contracts\Validation\Rule;
66
use LangleyFoxall\LaravelNISTPasswordRules\PasswordRules;
7-
use PHPUnit\Framework\TestCase;
7+
use Orchestra\Testbench\TestCase;
88

99
class PasswordRulesTest extends TestCase
1010
{

0 commit comments

Comments
 (0)