vee-validate and vue-i18n integration when using custom ruleVue JS 2.0 not rendering anything?Dynamic localization in vue-i18nvue-i18n doesn't update locale after integrating vuexVuejs 2: Unable to switch between tabbed formVueJS validation change locale during runtimeVue.js vee-validate custom dictionary setupHow to use Vuex state when creating custom validation with Vee ValidateImport library on local and call the library function on global to make validationUse I18n translation messages from SFC when using Vue.extendVue-i18n Integration by vee-validate not working as described in the documentation

What should you do when eye contact makes your subordinate uncomfortable?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

How can "mimic phobia" be cured or prevented?

Electoral considerations aside, what are potential benefits, for the US, of policy changes proposed by the tweet recognizing Golan annexation?

Mixing PEX brands

Did arcade monitors have same pixel aspect ratio as TV sets?

How does a computer interpret real numbers?

Can I visit Japan without a visa?

Is aluminum electrical wire used on aircraft?

Can a College of Swords bard use a Blade Flourish option on an opportunity attack provoked by their own Dissonant Whispers spell?

Angel of Condemnation - Exile creature with second ability

What is going on with 'gets(stdin)' on the site coderbyte?

How do you make your own symbol when Detexify fails?

How does the math work for Perception checks?

How to cover method return statement in Apex Class?

How to hide some fields of struct in C?

Does Doodling or Improvising on the Piano Have Any Benefits?

The IT department bottlenecks progress. How should I handle this?

Biological Blimps: Propulsion

Are Captain Marvel's powers affected by Thanos' actions in Infinity War

How could a planet have erratic days?

How much character growth crosses the line into breaking the character

What should you do if you miss a job interview (deliberately)?

Mimic lecturing on blackboard, facing audience



vee-validate and vue-i18n integration when using custom rule


Vue JS 2.0 not rendering anything?Dynamic localization in vue-i18nvue-i18n doesn't update locale after integrating vuexVuejs 2: Unable to switch between tabbed formVueJS validation change locale during runtimeVue.js vee-validate custom dictionary setupHow to use Vuex state when creating custom validation with Vee ValidateImport library on local and call the library function on global to make validationUse I18n translation messages from SFC when using Vue.extendVue-i18n Integration by vee-validate not working as described in the documentation













0















This is a question about the integration of vee-validate and vue-i18n + additional error message for a custom rule. I could get every single detail to work alone, but not the whole combination (this is the excuse for the long question).



The program flow is as follows:



  1. A web page containing vue.js component loads from server. The vue.js component loads vee-validate and vue-i18n and defines a custom rule. It does not pre-load any language data - so on created() it checks the language of the container web page and loads it's localized texts from the server via ajax call.


  2. It is straightforward to set these messages to the vue-i18n simply so:



    this.$i18n.mergeLocaleMessage(localeName, newLocaleMessages)



  3. Somehow I have to tell vee-validate to change its language also ...
    I want to load the corresponding vee-validate locale with its default error messages


and



I want to add my custom error message translation to the validation messages.



And here I have the problems



While it is possible to pre-load all needed vee-validate localisations like so:



import en from 'vee-validate/dist/locale/en'
...
import de from 'vee-validate/dist/locale/de'
...
Vue.use(VeeValidate,
i18nRootKey: 'validations',
i18n,
dictionary:
en: en
...
de: de

)


I do not want to do it as it does not make sense to load multile data if the component won't use it.



It is better to load the data dynamically.



And if one does not use vue-i18n it works perfectly like that:



if (this.$validator.dictionary.hasLocale(localeName)) 
this.$validator.localize(localeName);
else
import(`vee-validate/dist/locale/$localeName`).then(locale =>
this.$validator.localize(localeName, locale);
);


/from ajax/ -> custom_dictionary =
/localeName/ :
messages:
customMessage: "TRanslation in /localeName/"


;

this.$validator.localize(custom_dictionary);


But then I want to use vue-i18n. So this.$validator... does not work anymore.
One also has to load the default language explicitly:



Vue.use(VeeValidate, 
i18nRootKey: 'validations',
i18n,
dictionary:
en: en

)


and when I try:



import(`vee-validate/dist/locale/$localeName`).then(locale => {
this.$i18n.mergeLocaleMessage(localeName, locale)
or
this.$i18n.mergeLocaleMessage(localeName, locale.messages)
or
this.$i18n.mergeLocaleMessage(localeName, locale.default.messages)


it does not work (the corresponding object in $i18n is created but stays empty).



Is there another syntax that would work?



It is somehow awkward that one cannot just call a method like $validator.loadLanguage(localeName).then(set it to i18n).



One also cannot define by the custom rule something like:



getMessage : () => get the message from $i18n using this key 


as the getMessage function is called only once with the currently loaded language.



Another restriction is that the message key should be the name of the custom rule - so every time I get it from the API I have to create new object with that name and pass it to the vv validator to localize it (put it in the corrsponding dictionary).



So at the end I actually cannot understand what is the profit to use vee-validate integrated with $i18n? I would consider to use them just separately. Or where am I wrong?



Any ideas for flawless integration are much appreciated. Thanks in advance!










share|improve this question


























    0















    This is a question about the integration of vee-validate and vue-i18n + additional error message for a custom rule. I could get every single detail to work alone, but not the whole combination (this is the excuse for the long question).



    The program flow is as follows:



    1. A web page containing vue.js component loads from server. The vue.js component loads vee-validate and vue-i18n and defines a custom rule. It does not pre-load any language data - so on created() it checks the language of the container web page and loads it's localized texts from the server via ajax call.


    2. It is straightforward to set these messages to the vue-i18n simply so:



      this.$i18n.mergeLocaleMessage(localeName, newLocaleMessages)



    3. Somehow I have to tell vee-validate to change its language also ...
      I want to load the corresponding vee-validate locale with its default error messages


    and



    I want to add my custom error message translation to the validation messages.



    And here I have the problems



    While it is possible to pre-load all needed vee-validate localisations like so:



    import en from 'vee-validate/dist/locale/en'
    ...
    import de from 'vee-validate/dist/locale/de'
    ...
    Vue.use(VeeValidate,
    i18nRootKey: 'validations',
    i18n,
    dictionary:
    en: en
    ...
    de: de

    )


    I do not want to do it as it does not make sense to load multile data if the component won't use it.



    It is better to load the data dynamically.



    And if one does not use vue-i18n it works perfectly like that:



    if (this.$validator.dictionary.hasLocale(localeName)) 
    this.$validator.localize(localeName);
    else
    import(`vee-validate/dist/locale/$localeName`).then(locale =>
    this.$validator.localize(localeName, locale);
    );


    /from ajax/ -> custom_dictionary =
    /localeName/ :
    messages:
    customMessage: "TRanslation in /localeName/"


    ;

    this.$validator.localize(custom_dictionary);


    But then I want to use vue-i18n. So this.$validator... does not work anymore.
    One also has to load the default language explicitly:



    Vue.use(VeeValidate, 
    i18nRootKey: 'validations',
    i18n,
    dictionary:
    en: en

    )


    and when I try:



    import(`vee-validate/dist/locale/$localeName`).then(locale => {
    this.$i18n.mergeLocaleMessage(localeName, locale)
    or
    this.$i18n.mergeLocaleMessage(localeName, locale.messages)
    or
    this.$i18n.mergeLocaleMessage(localeName, locale.default.messages)


    it does not work (the corresponding object in $i18n is created but stays empty).



    Is there another syntax that would work?



    It is somehow awkward that one cannot just call a method like $validator.loadLanguage(localeName).then(set it to i18n).



    One also cannot define by the custom rule something like:



    getMessage : () => get the message from $i18n using this key 


    as the getMessage function is called only once with the currently loaded language.



    Another restriction is that the message key should be the name of the custom rule - so every time I get it from the API I have to create new object with that name and pass it to the vv validator to localize it (put it in the corrsponding dictionary).



    So at the end I actually cannot understand what is the profit to use vee-validate integrated with $i18n? I would consider to use them just separately. Or where am I wrong?



    Any ideas for flawless integration are much appreciated. Thanks in advance!










    share|improve this question
























      0












      0








      0








      This is a question about the integration of vee-validate and vue-i18n + additional error message for a custom rule. I could get every single detail to work alone, but not the whole combination (this is the excuse for the long question).



      The program flow is as follows:



      1. A web page containing vue.js component loads from server. The vue.js component loads vee-validate and vue-i18n and defines a custom rule. It does not pre-load any language data - so on created() it checks the language of the container web page and loads it's localized texts from the server via ajax call.


      2. It is straightforward to set these messages to the vue-i18n simply so:



        this.$i18n.mergeLocaleMessage(localeName, newLocaleMessages)



      3. Somehow I have to tell vee-validate to change its language also ...
        I want to load the corresponding vee-validate locale with its default error messages


      and



      I want to add my custom error message translation to the validation messages.



      And here I have the problems



      While it is possible to pre-load all needed vee-validate localisations like so:



      import en from 'vee-validate/dist/locale/en'
      ...
      import de from 'vee-validate/dist/locale/de'
      ...
      Vue.use(VeeValidate,
      i18nRootKey: 'validations',
      i18n,
      dictionary:
      en: en
      ...
      de: de

      )


      I do not want to do it as it does not make sense to load multile data if the component won't use it.



      It is better to load the data dynamically.



      And if one does not use vue-i18n it works perfectly like that:



      if (this.$validator.dictionary.hasLocale(localeName)) 
      this.$validator.localize(localeName);
      else
      import(`vee-validate/dist/locale/$localeName`).then(locale =>
      this.$validator.localize(localeName, locale);
      );


      /from ajax/ -> custom_dictionary =
      /localeName/ :
      messages:
      customMessage: "TRanslation in /localeName/"


      ;

      this.$validator.localize(custom_dictionary);


      But then I want to use vue-i18n. So this.$validator... does not work anymore.
      One also has to load the default language explicitly:



      Vue.use(VeeValidate, 
      i18nRootKey: 'validations',
      i18n,
      dictionary:
      en: en

      )


      and when I try:



      import(`vee-validate/dist/locale/$localeName`).then(locale => {
      this.$i18n.mergeLocaleMessage(localeName, locale)
      or
      this.$i18n.mergeLocaleMessage(localeName, locale.messages)
      or
      this.$i18n.mergeLocaleMessage(localeName, locale.default.messages)


      it does not work (the corresponding object in $i18n is created but stays empty).



      Is there another syntax that would work?



      It is somehow awkward that one cannot just call a method like $validator.loadLanguage(localeName).then(set it to i18n).



      One also cannot define by the custom rule something like:



      getMessage : () => get the message from $i18n using this key 


      as the getMessage function is called only once with the currently loaded language.



      Another restriction is that the message key should be the name of the custom rule - so every time I get it from the API I have to create new object with that name and pass it to the vv validator to localize it (put it in the corrsponding dictionary).



      So at the end I actually cannot understand what is the profit to use vee-validate integrated with $i18n? I would consider to use them just separately. Or where am I wrong?



      Any ideas for flawless integration are much appreciated. Thanks in advance!










      share|improve this question














      This is a question about the integration of vee-validate and vue-i18n + additional error message for a custom rule. I could get every single detail to work alone, but not the whole combination (this is the excuse for the long question).



      The program flow is as follows:



      1. A web page containing vue.js component loads from server. The vue.js component loads vee-validate and vue-i18n and defines a custom rule. It does not pre-load any language data - so on created() it checks the language of the container web page and loads it's localized texts from the server via ajax call.


      2. It is straightforward to set these messages to the vue-i18n simply so:



        this.$i18n.mergeLocaleMessage(localeName, newLocaleMessages)



      3. Somehow I have to tell vee-validate to change its language also ...
        I want to load the corresponding vee-validate locale with its default error messages


      and



      I want to add my custom error message translation to the validation messages.



      And here I have the problems



      While it is possible to pre-load all needed vee-validate localisations like so:



      import en from 'vee-validate/dist/locale/en'
      ...
      import de from 'vee-validate/dist/locale/de'
      ...
      Vue.use(VeeValidate,
      i18nRootKey: 'validations',
      i18n,
      dictionary:
      en: en
      ...
      de: de

      )


      I do not want to do it as it does not make sense to load multile data if the component won't use it.



      It is better to load the data dynamically.



      And if one does not use vue-i18n it works perfectly like that:



      if (this.$validator.dictionary.hasLocale(localeName)) 
      this.$validator.localize(localeName);
      else
      import(`vee-validate/dist/locale/$localeName`).then(locale =>
      this.$validator.localize(localeName, locale);
      );


      /from ajax/ -> custom_dictionary =
      /localeName/ :
      messages:
      customMessage: "TRanslation in /localeName/"


      ;

      this.$validator.localize(custom_dictionary);


      But then I want to use vue-i18n. So this.$validator... does not work anymore.
      One also has to load the default language explicitly:



      Vue.use(VeeValidate, 
      i18nRootKey: 'validations',
      i18n,
      dictionary:
      en: en

      )


      and when I try:



      import(`vee-validate/dist/locale/$localeName`).then(locale => {
      this.$i18n.mergeLocaleMessage(localeName, locale)
      or
      this.$i18n.mergeLocaleMessage(localeName, locale.messages)
      or
      this.$i18n.mergeLocaleMessage(localeName, locale.default.messages)


      it does not work (the corresponding object in $i18n is created but stays empty).



      Is there another syntax that would work?



      It is somehow awkward that one cannot just call a method like $validator.loadLanguage(localeName).then(set it to i18n).



      One also cannot define by the custom rule something like:



      getMessage : () => get the message from $i18n using this key 


      as the getMessage function is called only once with the currently loaded language.



      Another restriction is that the message key should be the name of the custom rule - so every time I get it from the API I have to create new object with that name and pass it to the vv validator to localize it (put it in the corrsponding dictionary).



      So at the end I actually cannot understand what is the profit to use vee-validate integrated with $i18n? I would consider to use them just separately. Or where am I wrong?



      Any ideas for flawless integration are much appreciated. Thanks in advance!







      javascript vue.js vuejs2 vee-validate vue-i18n






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      Alexander MihailovAlexander Mihailov

      14329




      14329






















          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280860%2fvee-validate-and-vue-i18n-integration-when-using-custom-rule%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280860%2fvee-validate-and-vue-i18n-integration-when-using-custom-rule%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript