Pristine icon indicating copy to clipboard operation
Pristine copied to clipboard

Allow for default messages to be localized

Open nicolasbinet opened this issue 4 years ago • 16 comments

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

Thanks.

nicolasbinet avatar Oct 04 '20 14:10 nicolasbinet

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

kevinmu17 avatar Feb 17 '21 15:02 kevinmu17

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

kevinmu17 avatar Feb 18 '21 09:02 kevinmu17

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

kevinmu17 avatar Mar 18 '21 17:03 kevinmu17

@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

sha256 avatar Mar 18 '21 17:03 sha256

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 avatar Mar 18 '21 17:03 kevinmu17

@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

sha256 avatar Mar 18 '21 20:03 sha256

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

kevinmu17 avatar Mar 19 '21 09:03 kevinmu17

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?

kevinmu17 avatar Mar 19 '21 09:03 kevinmu17

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.

manchumahara avatar Jun 23 '21 11:06 manchumahara

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

or3lie avatar Jan 17 '23 09:01 or3lie

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",
  },

kevinmu17 avatar Jan 17 '23 09:01 kevinmu17

ok, thank you for the help

or3lie avatar Jan 17 '23 09:01 or3lie

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?

thomas-franz avatar Feb 08 '23 17:02 thomas-franz

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 avatar Feb 09 '23 07:02 sha256

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

thomas-franz avatar Feb 09 '23 08:02 thomas-franz

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];
    });
};

yevheniiorhanistyi avatar Mar 28 '24 11:03 yevheniiorhanistyi