Skip to content

Commit

Permalink
Merge pull request #27 from atymic/fix-translations
Browse files Browse the repository at this point in the history
fix: fix translations + update readme
  • Loading branch information
freekmurze committed Jun 13, 2019
2 parents afb93c0 + 90e51ba commit 2180a33
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 15 deletions.
7 changes: 7 additions & 0 deletions README.md
Expand Up @@ -18,6 +18,13 @@ composer require spatie/laravel-validation-rules

The package will automatically register itself.

### Translations

If you wish to edit the package translations, you can run the following command to publish them into your `resources/lang` folder

```bash
php artisan vendor:publish --provider="Spatie\ValidationRules\ValidationRulesServiceProvider"
```

## Available rules

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Rules/Authorized.php
Expand Up @@ -45,7 +45,7 @@ public function message(): string
{
$classBasename = class_basename($this->className);

return __('validation.authorized', [
return __('validationRules::messages.authorized', [
'attribute' => $this->attribute,
'ability' => $this->ability,
'className' => $classBasename,
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/CountryCode.php
Expand Up @@ -40,7 +40,7 @@ public function passes($attribute, $value): bool

public function message(): string
{
return __('validation.country_code', [
return __('validationRules::messages.country_code', [
'attribute' => $this->attribute,
]);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Rules/Delimited.php
Expand Up @@ -87,7 +87,7 @@ public function passes($attribute, $value)

if (! is_null($this->minimum)) {
if ($items->count() < $this->minimum) {
$this->message = __('validation.delimited.min', [
$this->message = __('validationRules::messages.delimited.min', [
'minimum' => $this->minimum,
'actual' => $items->count(),
'item' => Str::plural($this->validationMessageWord, $items->count()),
Expand All @@ -99,7 +99,7 @@ public function passes($attribute, $value)

if (! is_null($this->maximum)) {
if ($items->count() > $this->maximum) {
$this->message = __('validation.delimited.max', [
$this->message = __('validationRules::messages.delimited.max', [
'maximum' => $this->maximum,
'actual' => $items->count(),
'item' => Str::plural($this->validationMessageWord, $items->count()),
Expand Down Expand Up @@ -127,7 +127,7 @@ public function passes($attribute, $value)

if (! $this->allowDuplicates) {
if ($items->unique()->count() !== $items->count()) {
$this->message = __('validation.delimited.unique');
$this->message = __('validationRules::messages.delimited.unique');

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Enum.php
Expand Up @@ -28,7 +28,7 @@ public function message(): string
{
$validValues = implode(', ', $this->validValues);

return __('validation.enum', [
return __('validationRules::messages.enum', [
'attribute' => $this->attribute,
'validValues' => $validValues,
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/ModelsExist.php
Expand Up @@ -44,7 +44,7 @@ public function message(): string

$classBasename = class_basename($this->modelClassName);

return __('validation.model_ids', [
return __('validationRules::messages.model_ids', [
'attribute' => $this->attribute,
'model' => $classBasename,
'modelAttribute' => $this->modelAttribute,
Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/AuthorizedTest.php
Expand Up @@ -81,8 +81,8 @@ public function it_will_return_false_if_the_gate_returns_false()
public function it_passes_attribute_ability_and_class_name_to_the_validation_message()
{
Lang::addLines([
'validation.authorized' => ':attribute :ability and :className',
], Lang::getLocale());
'messages.authorized' => ':attribute :ability and :className',
], Lang::getLocale(), 'validationRules');

$rule = new Authorized('edit', TestModel::class);

Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/CountryCodeTest.php
Expand Up @@ -44,8 +44,8 @@ public function it_can_be_a_nullable_country_code_field()
public function it_passes_the_attribute_name_to_the_validation_message()
{
Lang::addLines([
'validation.country_code' => ':attribute',
], Lang::getLocale());
'messages.country_code' => ':attribute',
], Lang::getLocale(), 'validationRules');

$rule = new CountryCode();

Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/EnumTest.php
Expand Up @@ -22,8 +22,8 @@ public function it_will_return_true_for_a_value_that_is_part_of_the_enum()
public function it_passes_attribute_and_valid_values_to_the_validation_message()
{
Lang::addLines([
'validation.enum' => ':attribute :validValues',
], Lang::getLocale());
'messages.enum' => ':attribute :validValues',
], Lang::getLocale(), 'validationRules');

$rule = new Enum(TestEnum::class);

Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/ModelsExistTest.php
Expand Up @@ -42,8 +42,8 @@ public function it_can_validate_existence_of_models_by_column()
public function it_passes_relevant_data_to_the_validation_message()
{
Lang::addLines([
'validation.model_ids' => ':attribute :model :modelAttribute :modelIds',
], Lang::getLocale());
'messages.model_ids' => ':attribute :model :modelAttribute :modelIds',
], Lang::getLocale(), 'validationRules');

$rule = new ModelsExist(User::class, 'id');

Expand Down

0 comments on commit 2180a33

Please sign in to comment.