I18 and format error

hey! I create ajvFormats and want to change default error display
currently for example I have :
must match format “email”
I’ve added translator to display keys in jsonforms and see this but nothing else
Can you confirm that I’ve to use
must match format “email”
as the translate key ?

my ajv
const formats = {
email: {
type: ‘string’,
validate: (data: string) => /[1]+@[^\s@]+.[^\s@]+$/.test(data),
errorMessageKey: ‘validation_emailInvalid’,
errorMessage: “URL invalid - must begin with https://”,
},
phone: {
type: ‘string’,
validate: (data: string) => /^+[0-9]+$/.test(data),
errorMessageKey: ‘validation_phoneInvalid’,
errorMessage: “URL invalid - must begin with https://”,
},
url: {
type: ‘string’,
validate: (data: string) => /^https://.+/.test(data),
error: {
message: “ddddd”
},
errorMessageKey: ‘validation_urlInvalid’,
errorMessage: “URL invalid - must begin with https://”,
},
xlinkedin: {
type: ‘string’,
validate: (data: string) => /^https://(www.)?linkedin.com/(in|company)/[\w-]+/?$/.test(data),
errorMessageKey: ‘validation_linkedinInvalid’,
errorMessage: “URL invalid - must begin with https://”,

},};

export const xcreateAjv = () => {
const myAjv = new Ajv({
//createAjv({
allErrors: true,
verbose: true,
$data: true,
strict: false,
messages: true
});

ajvErrors(myAjv);
addFormats(myAjv);

Object.entries(formats).forEach(([name, format]) => {
  myAjv.addFormat(name, format.validate);

  const schema = {
    type: 'string',
    format: name,
    errorMessage: {
      format: format.errorMessage
    }
  };

  myAjv.addSchema(schema, `${name}Schema`);
});

// errorMessage: String(i18n.t(format.errorMessageKey)),//{
//format: String(i18n.t(format.errorMessageKey))
//format: String(format.errorMessageKey)
//}


  1. ^\s@ ↩︎

Hi @clysss,

I don’t see where JSON Forms comes into play in this scenario. I don’t think there is any built-in translation mechanism in Ajv. What they offer is a map of all predefined messages to other languages, see the ajv-i18n plugin.

If you would like to leverage JSON Forms built-in i18n support, then see this documentation.

Ok:) thx for your input. I’ll use errormessage in json, will be easier;)