You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem here is that even though it's properly translating the error message, formio.js is passing an un-translated string into it:
message(component){// "required" is translated...// ↓returncomponent.t(component.errorMessage('required'),{field: component.errorLabel,// ← but the error label placeholder is notdata: component.data});}
In this case, it's using the correct required translation ("{{field}} es requerido"), and interpolating the {{field}} placeholder with the un-translated label ("Your name") instead of the translation of the field's label ("Su nombre").
Workaround
I believe the workaround is to add Phrase translations for {key}.validate.customMessage, as formio.js's validation logic appears to prefer the component's validate.customMessage property over the message of the validation(s) that failed. In this case, the name.validate.customMessage Phrase translations could be "Your name is required" in English and "Su nombre es requerido" in Spanish.
Patch
The place to patch this is in the errorLabel getter of the Component class:
/** * Returns the error label for this component. * @return {*} */geterrorLabel(){returnthis.t(this.component.errorLabel||this.component.label||this.component.placeholder||this.key);}
For our case (Phrase translations with predictable keys), we'd patch it as something like this:
This approach would give us more fine-grained control over how any of the interpolated strings are translated. We could even iterate over all the keys of the params object and translate any that are strings. 🤷
Well, this is not great:
The problem here is that even though it's properly translating the error message, formio.js is passing an un-translated string into it:
In this case, it's using the correct
required
translation ("{{field}} es requerido"), and interpolating the{{field}}
placeholder with the un-translated label ("Your name") instead of the translation of the field's label ("Su nombre").Workaround
I believe the workaround is to add Phrase translations for
{key}.validate.customMessage
, as formio.js's validation logic appears to prefer the component'svalidate.customMessage
property over the message of the validation(s) that failed. In this case, thename.validate.customMessage
Phrase translations could be "Your name is required" in English and "Su nombre es requerido" in Spanish.Patch
The place to patch this is in the
errorLabel
getter of the Component class:For our case (Phrase translations with predictable keys), we'd patch it as something like this:
The text was updated successfully, but these errors were encountered: