aurelia / validatejs

Enables expressive validation using decorators and/or a fluent API.
MIT License
22 stars 23 forks source link

i18n support #27

Closed plwalters closed 8 years ago

plwalters commented 8 years ago

As @alvarezmario mentioned -

alvarezmario commented 2 days ago This was a recurring issue with the previous aurelia validation library. Most people agree on using aurelia-i18n to handle this, which is indeed the best possible way. Have this been taken into account? I don't see any issue here related to it.

Regards

jadrake75 commented 8 years ago

This would only be a problem if you are going to use the default messaging right? if you are going to use message options than you could provide the translations within the javascript code (assuming the fluent form here)

One option here is to provide options with the plugin configuration. Default to use i18n aurelia library but provide a way to turn that off, and even potentially allow a message or other format to be a "key" vs. a physical message?

JeroenVinke commented 8 years ago

I'm using the following hack in main.js to translate messages through i18n:

  import validate                  from 'validate.js';
  import {I18N}                    from 'aurelia-i18n';

  // somewhere in the configure method
  let i18n = aurelia.container.get(I18N);

  validate.options = {fullMessages: false};
  validate.format = (msg, params) => {
    return i18n.tr(msg, params;
  }

Also, you may have to make validate.js a dependency of your app: jspm install validate.js=npm:validate.js

This is what my translation.json contains:

  "is not equal to %{attribute}": "Moet gelijk zijn aan {{attribute}}",
  "is too short (minimum is %{count} characters)": "Moet minimaal {{count}} karakters lang zijn",
  "can't be blank": "Mag niet leeg zijn"
vit3k commented 8 years ago

@JeroenVinke Maybe it's not directly related to the issue but how do you get to load validate.js in you main.js file? I'm getting systemjs error that validate.js can't be found. It exists in jspm_packages/npm. I think I still don't understand how system.js works...

JeroenVinke commented 8 years ago

@vit3k I think you need to install it as a dependency of your app (the fact that it's a dependency of aurelia-validatejs is not enough): jspm install validate.js=npm:validate.js

vit3k commented 8 years ago

@JeroenVinke thanks, now it's working.

jdanyow commented 8 years ago

see docs