validatorjs icon indicating copy to clipboard operation
validatorjs copied to clipboard

Global attribute names for language

Open alisherafat01 opened this issue 8 years ago • 5 comments

I know how to set custom attribute names for an instance of validator but I want to know is it possible to set them globally? (i need something like below): var validator = require('validatorjs'); validator.useLang('fa'); validator.setAttributes('fa',{ age: 'سن', full_name: 'نام کامل', ... });

alisherafat01 avatar Jun 26 '17 14:06 alisherafat01

Any progress on this issue?

alisherafat01 avatar Feb 28 '18 09:02 alisherafat01

Hi, I am not a library owner, so my opinion may be different and not committed to be the true one.

As I understand you need something like global .setAttributeNames. Here is what I think.

class Validator is responsible for creating a validator instance. And as it is a constructor it defines the properties and methods for instance and holds some generic data. Class Validator does not interact with your form and knows nothing about your form fields(and about your form at all), but instance (validator) does.

Following your request, you are asking to break an encapsulation - in my opinion, this does not look good from the architectural point of view. The current implementation allows keeping some separation or responsibilities and roles.

What do you think?

Btw, @alisherafat can you help with one rule translation into Persian('fa') language? it is a "hex" rule https://github.com/skaterdav85/validatorjs/blob/master/src/lang/fa.js Can you reply me with translation here?

vict-shevchenko avatar Feb 28 '18 11:02 vict-shevchenko

Hi @vict-shevchenko Translation of hex rule for fa_IR is: hex: 'فیلد :attribute باید در فرمت مبنای ۱۶ باشد'

As answered herer Laravel validator has option to modify attributeNames for a specific language globally and there is nothing wrong with that and is good thing to implement here.

actually attributes:{} property should be modifiable here

alisherafat01 avatar Feb 28 '18 15:02 alisherafat01

This has been tagged as a feature request and will consider this addition for a future release.

mikeerickson avatar Feb 28 '18 16:02 mikeerickson

Cool! Glad to know this. Thanks a lot for translation.

vict-shevchenko avatar Feb 28 '18 21:02 vict-shevchenko