somnambulist-tech / validation

A re-write of rakit/validation, a standalone validation library inspired by Laravel Validation
MIT License
44 stars 13 forks source link

Update Rule.php #21

Closed 1mahdimf closed 1 year ago

1mahdimf commented 1 year ago

use aliases in error messages good for non English languages

dave-redfern commented 1 year ago

@1mahdimf Thanks for your PR. I have a couple of questions for you.

Aliases will already be used in error messages if set on the validation rule or via calling Validation::setAlias before triggering validation. The alias is assigned to :attribute instead of the attribute key. This is covered in the FactoryTest::testArrayValidationWithAliases test method where the key product_id is replaced with Product ID. It is further possible to assign a completely translated message to a specific attribute by using the attributes name in the messages bag or the attribute name and a :<rule_name> for a specific rule.

If this does not meet your needs, then has some specific use case been missed? Do you have a test you can add to this PR that checks this behaviour to prevent later regressions?

dave-redfern commented 1 year ago

I am closing this PR, if you wish to re-submit / comment please do so. If re-submitting please be sure to include a test case that covers specifically what this addresses.