Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.7] Show displayable values for relative dates in validation error messages #27341

Merged
merged 1 commit into from
Jan 30, 2019

Conversation

sebdesign
Copy link
Contributor

Currently the after, after_or_equal, before, before_or_equal and date_equals validation rules allow us to use relative keywords in english to compare dates, e.g. date_equals:tomorrow.

When the placeholders are replaced in the validation messages, the :date parameter is normally replaced if it references another attribute, e.g. after:start_date but not when it's a relative keyword.

This is an issue when the locale is other than english: e.g. the date_equals:tomorrow in french is translated to Le champ date doit être une date égale à tomorrow.

This commit allows for developers to specify custom translation for these values.

E.g. in fr/validation.php:

'values' => [
    'date' => [
        'tomorrow' => 'demain',
    ],
],

So now the validation message will be translated to Le champ date doit être une date égale à demain.

Currently the `after`, `after_or_equal`, `before`, `before_or_equal` and `date_equals` validation rules allow us to use relative keywords in english to compare dates, e.g. `date_equals:tomorrow`.

When the placeholders are replaced in the validation messages, the `:date` parameter is normally replaced if it references another attribute, e.g. `after:start_date` but not when it's a relative keyword.

This is an issue when the locale is other than english: e.g. the `date_equals:tomorrow` in french is translated to `Le champ date doit être une date égale à tomorrow.`

This commit allows for developers to specify custom translation for these values.

E.g. in `fr/validation.php`:
```php
'values' => [
    'date' => [
        'tomorrow' => 'demain',
    ],
],
```

So now the validation message will be translated to `Le champ date doit être une date égale à demain.`
@driesvints driesvints changed the title Show displayable values for relative dates in validation error messages [5.7] Show displayable values for relative dates in validation error messages Jan 29, 2019
@taylorotwell
Copy link
Member

getDisplayableValue only takes 1 parameter. Why are you passing two?

@sebdesign
Copy link
Contributor Author

@taylorotwell if I'm not mistaken it actually takes two parameters:

public function getDisplayableValue($attribute, $value)

Is that correct?

@taylorotwell
Copy link
Member

Heh, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants