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

Projects
None yet
2 participants
@sebdesign
Copy link
Contributor

sebdesign commented Jan 28, 2019

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.

Show displayable values for relative dates in validation error messages
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

This comment has been minimized.

Copy link
Member

taylorotwell commented Jan 29, 2019

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

@sebdesign

This comment has been minimized.

Copy link
Contributor Author

sebdesign commented Jan 29, 2019

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

public function getDisplayableValue($attribute, $value)

Is that correct?

@taylorotwell

This comment has been minimized.

Copy link
Member

taylorotwell commented Jan 30, 2019

Heh, sorry.

@taylorotwell taylorotwell merged commit 3fd4405 into laravel:5.7 Jan 30, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment