Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate the validation errors #171

Open
ipetrov87 opened this issue Mar 6, 2018 · 1 comment
Open

Translate the validation errors #171

ipetrov87 opened this issue Mar 6, 2018 · 1 comment

Comments

@ipetrov87
Copy link

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.

@ipetrov87
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant