smallcontactform
smallcontactform copied to clipboard
Validation error messages for each language in Translate Messages Dictionary
Hello,
I've just noticed that form fields labels appear in dictionary in the default language, as expected, while validation error messages are added for each language, after the first post submit in that language
For example, "the company field is required" and "The email field is required" are two validation error for the default language in Translate messages datatable
And the corresponding records "company wird benötigt" and "email wird benötigt" are not useful, because traslations can be added to Default language records
What do you think about it?
Hello, I'm here again. I've realized that adding a validation error for each field solves the issue, each message is translatable as expected. Anyway, adding Translate Message records on form submit for default language only could be an idea. Thank you for your work!
Hello Jan,
I'm here again. I was wrong, even adding a validation error in the field definition, when the message is translated in a certain language, its translation in added in the Translate messages datatable as a new record
for example, "the company field is required" (in EN default language) once translated in Italian generates a new Translate Message Record "Il campo company è obbligatorio"
This is the unwantend entry
This should be avoided by creating Translate messages entries only when submitting the form in the site default language.
By the way, fields label behaviour is ok, they are not replicated even after translating them
Let me know what do you thing. Thank you
Hello Jan, I have a possible fix proposal In JanVince\SmallContactForm\Components\SmallContactForm row 658 change this row $output[] = '' . Settings::getDictionaryTranslated($this->postData[$fieldSettings['name']]['error']) . ""; to this $output[] = '' . $this->postData[$fieldSettings['name']]['error'] . "";
postData[$fieldSettings['name']]['error'] contains the right translation yet, so Settings::getDictionaryTranslated call should be removed
Hi @massimomegistus,
I believe this was some of the first try to translate validation messages.
I personally do not use this as I always create fields list for each locale (you can switch fields list to other locale by click on locale shortcut in right upper conner).
Hi @jan-vince, this specific site has 8 different locales, so I would prefer to avoid field repeater redefinition, but changing $output[] = '' . Settings::getDictionaryTranslated($this->postData[$fieldSettings['name']]['error']) . ""; to $output[] = '' . $this->postData[$fieldSettings['name']]['error'] . "";
solves the issue, because postData[$fieldSettings['name']]['error'] contains the translated error
$validationMessages[($field['name'] . '.' . $rule['validation_type'] )] = Settings::getDictionaryTranslated($rule['validation_error']);
and the additional getDictionaryTranslated call is not necesary. Do you agree?
I will keep this open and test it when I have a time. Thanks for issue!
You are welcome!
Hi @massimomegistus and sorry for the delay.
I have tested it and fixed in 1.62.0 version.
Thank you!
Hi @jan-vince , great!