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

Rule and custom Attribute on lang file #29

Closed kaxias closed 1 month ago

kaxias commented 2 months ago

Normally we do like this.

<?php

return [
    'rule.required' => 'The :attribute field is required.',
];

would be nice if we could do something like this.

<?php

return [
    'rule' => [
         'required' => 'The :attribute field is required.',
    ],

    'custom-attribute' => [
        'custom_field' => 'custom field',
    ],
];
dave-redfern commented 2 months ago

@kaxias you mean allowing nested arrays for defining translation messages?

Personally I am not a huge fan of heavily nested arrays for things like these. Do you have specific reasons?

messikiller commented 1 month ago

It is possible that the key of array maybe contains "." flag already. it would be better if the dot flag can be specified by the user...

dave-redfern commented 1 month ago

Closing due to lack of feedback. If there is an actual use case for changing the translation message format, I am more than happy to discuss it.

As an alternative: custom translations for custom attributes can be added using the dot format (see the docs). Copy the existing files and add whatever others you desire. If you really want nested arrays, then you can add a pre-processor that concats the array keys together before adding the messages to the Factory.