question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lang pt_BR may be broken

See original GitHub issue

I tested other langs but only pt_BR is giving an error. My code is like this:

let Validator = require('validatorjs');
Validator.useLang('pt_BR');
let rules: any = {
            nome: 'required|between:5,100',
            data_nascimento: ['required', 'regex:([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))'],
            cpf: 'required|size:11',
            sexo: 'required|size:1',
            escola_id: 'required'
        }

        let validation = new Validator(aluno, rules);

        validation.setAttributeNames({
            data_nascimento: "data de nascimento",
            escola_id: "escola"
        });

        if (validation.fails()) {
            console.log(validation.errors.all())
        }

And the error:

Cannot read property 'hasOwnProperty' of undefined
    at Messages._getAttributeName (path/node_modules/validatorjs/src/messages.js:52:41)
    at Messages._replacePlaceholders (path/node_modules/validatorjs/src/messages.js:136:27

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9

github_iconTop GitHub Comments

2reactions
jorgermduartecommented, May 19, 2020

@mtcarvalho I checked the resource files. Probably the same problem like last year. Just add the “attributes : {}” on the pt-br file and it will work.

image

2reactions
olavoparnocommented, Nov 28, 2018

Hello, mister @CFCSystem, We had the same problem here trying to use the Lang method but I came around with a temporary solution, that is to pass an object with all translations (you can copy from the very Lang pt_BR they supply) and pass it as argument as “custom attributes” in the new Validator.

E.g. let validation = new Validator(aluno, rules, { …customAttributes })

While this is not a real solution, it worked out just fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lang pt_BR may be broken · Issue #299 - GitHub
I tested other langs but only pt_BR is giving an error. My code is like this: let Validator = require('validatorjs'); Validator.
Read more >
How to set HTML lang attribute dynamically on NextJs ...
I believe the best solution here is to use a custom ./pages/_document.js file and override the document itself. import Document, { Html ...
Read more >
[root tip] [How To] Troubleshooting locale errors - Tutorials
I have written this using my system's locale - en_DK for messages and da_DK for the rest of the system. Check locale settings...
Read more >
BROKEN HOST in Licensing Information Occurs ... - Tableau
Activation becomes broken intermittently (**BROKEN** HOST Trust Flags in ... BROKEN HOST may occur in licensing information when a Tableau ...
Read more >
Supported languages and browsers | Docs - Twitter Developer
Pages which define an unsupported script or region will be mapped to the closest available language: e.g. pt-BR will use pt if Portuguese...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found