From d890c237fbd39b44640e5889d014d416df2b1e08 Mon Sep 17 00:00:00 2001 From: Davide Iadeluca Date: Sat, 12 Oct 2024 19:27:33 +0200 Subject: [PATCH] feat(core): implement translatable validation attribute errors --- framework/core/src/Api/ForgotPasswordValidator.php | 10 ++++++++++ .../core/src/Discussion/DiscussionValidator.php | 10 ++++++++++ framework/core/src/Group/GroupValidator.php | 11 +++++++++++ framework/core/src/Post/PostValidator.php | 10 ++++++++++ framework/core/src/User/UserValidator.php | 12 ++++++++++++ 5 files changed, 53 insertions(+) diff --git a/framework/core/src/Api/ForgotPasswordValidator.php b/framework/core/src/Api/ForgotPasswordValidator.php index 80f596c31f..8c57fdadd0 100644 --- a/framework/core/src/Api/ForgotPasswordValidator.php +++ b/framework/core/src/Api/ForgotPasswordValidator.php @@ -26,4 +26,14 @@ class ForgotPasswordValidator extends AbstractValidator protected $rules = [ 'email' => ['required', 'email'] ]; + + /** + * {@inheritdoc} + */ + protected function attributes() + { + return [ + 'email' => $this->translator->trans('validation.attributes.email') + ]; + } } diff --git a/framework/core/src/Discussion/DiscussionValidator.php b/framework/core/src/Discussion/DiscussionValidator.php index 15d2a329c7..884123164f 100644 --- a/framework/core/src/Discussion/DiscussionValidator.php +++ b/framework/core/src/Discussion/DiscussionValidator.php @@ -20,4 +20,14 @@ class DiscussionValidator extends AbstractValidator 'max:80' ] ]; + + /** + * {@inheritdoc} + */ + protected function attributes() + { + return [ + 'title' => $this->translator->trans('validation.attributes.title') + ]; + } } diff --git a/framework/core/src/Group/GroupValidator.php b/framework/core/src/Group/GroupValidator.php index e1e09cfe3b..0e10e9394d 100644 --- a/framework/core/src/Group/GroupValidator.php +++ b/framework/core/src/Group/GroupValidator.php @@ -17,4 +17,15 @@ class GroupValidator extends AbstractValidator 'name_singular' => ['required'], 'name_plural' => ['required'] ]; + + /** + * {@inheritdoc} + */ + protected function attributes() + { + return [ + 'name_singular' => $this->translator->trans('validation.attributes.name_singular'), + 'name_plural' => $this->translator->trans('validation.attributes.name_plural'), + ]; + } } diff --git a/framework/core/src/Post/PostValidator.php b/framework/core/src/Post/PostValidator.php index 267cd46612..cbd8b716c1 100644 --- a/framework/core/src/Post/PostValidator.php +++ b/framework/core/src/Post/PostValidator.php @@ -19,4 +19,14 @@ class PostValidator extends AbstractValidator 'max:65535' ] ]; + + /** + * {@inheritdoc} + */ + protected function attributes() + { + return [ + 'content' => $this->translator->trans('validation.attributes.content') + ]; + } } diff --git a/framework/core/src/User/UserValidator.php b/framework/core/src/User/UserValidator.php index bd24ec34d7..f8f5424175 100644 --- a/framework/core/src/User/UserValidator.php +++ b/framework/core/src/User/UserValidator.php @@ -70,4 +70,16 @@ protected function getMessages() 'username.regex' => $this->translator->trans('core.api.invalid_username_message') ]; } + + /** + * {@inheritdoc} + */ + protected function attributes() + { + return [ + 'username' => $this->translator->trans('validation.attributes.username'), + 'email' => $this->translator->trans('validation.attributes.email'), + 'password' => $this->translator->trans('validation.attributes.password') + ]; + } }