Skip to content

Interface: SetI18nCallback()<T>

Callback function type for setting up internationalization.

This function is used to configure the i18n system by providing a translation callback. Once called, it sets up the root validator instance to use the provided translation function for all validation messages.

Example

typescript
// Set up Spanish translations
validator.$setI18n((term: string) => {
  return spanishTranslations[term] || term;
});

// Set up with external i18n library
validator.$setI18n((term: string) => {
  return i18next.t(`validation.${term}`, { defaultValue: term });
});

Type Parameters

Type ParameterDefault type
TRoot
ts
SetI18nCallback(this: T, callback: I18nCallback): T;

Callback function type for setting up internationalization.

This function is used to configure the i18n system by providing a translation callback. Once called, it sets up the root validator instance to use the provided translation function for all validation messages.

Parameters

ParameterTypeDescription
thisT-
callbackI18nCallbackThe I18nCallback function that will handle message translation

Returns

T

Example

typescript
// Set up Spanish translations
validator.$setI18n((term: string) => {
  return spanishTranslations[term] || term;
});

// Set up with external i18n library
validator.$setI18n((term: string) => {
  return i18next.t(`validation.${term}`, { defaultValue: term });
});