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.

Q: Custom methods and messages when using i18n

See original GitHub issue

Versions

  • vee-validate: 2.1.0-beta6
  • vue: 2.5.2

Hello, I was trying to follow the documentation here: https://baianat.github.io/vee-validate/guide/localization.html

I am unable to figure how to replace the message thrown by required and at the same time merge my own custom messages.

So far this is what I have done but it is awful and will not work with dynamically generated fields:

https://codesandbox.io/s/pkoo113447

Is there a way I could add a method to validaton.js such as:

required: () => 'This field is required.' 

Or any other to fix this?

Thank you

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
logaretmcommented, Jul 25, 2018

Sorry for the late response, like @nicokoenig pointed out the dictionary API allows you to do all of these things, I think the docs could be revisited to make things clearer about the localization.

Thanks @nicokoenig for keeping an eye out and responding for these issues, much appreciated!

1reaction
nicokoenigcommented, Jul 24, 2018

Okay, there is even a more simple approach.

You can simply do this:

const customMessages = {
  en: {
    messages: {
      required: 'Yo, this field is required!'
    }
  }
}

// For initial setup and assuming you imported Validator from `vee-validate`
Validator.localize(customMessages);

// Inside a component
this.$validator.localize(customMessages);

This is also described in the docs, so no need for a PR 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Q: Custom methods and messages when using i18n ... - GitHub
In our application, we use vue-i18n and store custom messages there. We use lazy loading for the i18n locale files and the vee-validate...
Read more >
Ruby on Rails i18n - Want To Translate Custom Messages in ...
Custom validation with i18n message: ... To make your models cleaner, you can create a custom validation helper method in an entirely new ......
Read more >
i18n in Java 11, Spring Boot, and JavaScript - Okta Developer
Learn how to internationalize and localize your Java and Spring Boot apps.
Read more >
KI18n - Programmer's Guide - KDE API Reference
Most messages can be internationalized with simple i18n* calls, which are described in the section gen_usage. A few messages may require treatment with...
Read more >
Advanced Features: Internationalized Routing - Next.js
Next.js has built-in support for internationalized (i18n) routing since v10.0.0 . You can provide a list of locales, the default locale, and domain-specific ......
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