sha256/Pristine

Allow for default messages to be localized

Opened this issue · 16 comments

This would be nice to be able to localize, or change, default errors message.
Maybe though the defaultConfig parameter ?

Thanks.

Would be nice to have a default config option like errorText :)

Oh, I see this commit c820761 but somehow can't seem to get it to work. It gives me an error:
.setLocale is not a function

@sha256 can you maybe point us in the right direction here??

@kevinmu17, sorry I have been very busy lately. Please see the last 2 test cases from here:

https://github.com/sha256/Pristine/blob/feature/i18n/test/locale.test.js

Thanks for the reply! I'm trying to test addMessages now, but same result:
Pristine.addMessages is not a function.

Both examples below are not working :(

import Pristine from 'pristinejs';

Pristine.addMessages('en', {
    'email': "Email not valid"
})
let pristine = new Pristine(form, defaultConfig, true);
pristine.addMessages('en', {
    'email': "Email not valid"
})

@kevinmu17, could you please double check if you're using the right lib files?
from here: https://github.com/sha256/Pristine/tree/feature/i18n/dist

Yes, checked my output and it says: "./node_modules/pristinejs/dist/pristine.js"

I installed the plugin with NPM, it seems the code isn't on there. I crosschecked it with the files on github and addMessages is no where to be found. Does pristine needs an update on NPM?

As I found the npm version and the last released version in github are not same file but npm package.json file saying same version. That is why 'addMessages' function is not available in npm version to be clear as I just checked. BTW, it's a nice library.

Hello, I installed Pristine with yarn and I can't use setLocale (I need to set french verion for error messages)
Is there an update planned for this point or how can I set my messages to french without that ?
Thanks

Hello, I installed Pristine with yarn and I can't use setLocale (I need to set french verion for error messages) Is there an update planned for this point or how can I set my messages to french without that ? Thanks

This repo is abandoned. a fix you can do is get the github repo link:

pacakage.json

 "dependencies": {
    "pristinejs": "git+https://github.com/sha256/Pristine.git",
  },

ok, thank you for the help

Hey @sha256! First of all, thank you for your effort in creating and maintaining this validator.
Could you please create a new version and publish it to NPM?

Hey @thomas-franz, thanks for the nudge and sorry for not maintaining it properly. I have just bumped the version and published to NPM.

@sha256 thank you so much! Is there any way to buy you a coffee? :)

Solved the problem in the local copy of node_modules in this way:

Pristine.prototype.setLocale = function (locale) {
    currentLocale = locale;
};
Pristine.prototype.addMessages = function (locale, messages) {
    var langObj = lang.hasOwnProperty(locale) ? lang[locale] : lang[locale] = {};

    Object.keys(messages).forEach(function (key, index) {
      langObj[key] = messages[key];
    });
};