amforms
amforms copied to clipboard
Translate the validation errors
I have been using the plugin to make a contact form for one of my client. It is the great plugin and save me a lot of work. Now the client want to have the form validation messages like "Name cannot be blank." to be translated to same language that is the entire site, which is not English. I am trying to done from several hours and I am still not done. To submit the form I am using the Ajax example from here.
I done a very simple solution until we get the general one. So here it is if someone else need it:
Open a file craft\plugins\amforms\controllers\AmForms_SubmissionsController.php at line 201 then replace this:
if (craft()->request->isAjaxRequest()) {
$return = array(
'success' => false,
'errors' => $submission->getErrors()
);
$this->returnJson($return);
}
with this:
if (craft()->request->isAjaxRequest()) {
$translated = $submission->getErrors();
foreach ($translated as $field => $errors) {
foreach ($errors as $error => $errorText) {
$translated[$field][$error] = Craft::t($errorText);
}
}
$return = array(
'success' => false,
'errors' => $translated
);
$this->returnJson($return);
}
And finally add the translation of the error for each field to the translation file in craft\app\translations
Hope soon we will have a general solution to this issue.