<p>The AJAX POST url variable (<code>postUrl</code>) should be set from the form template with this Twig code:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    var postUrl;
    if ('{{ craft.i18n.getCurrentLocale() }}' == '{{ craft.i18n.getPrimarySiteLocale() }}') {
        postUrl = '/';
    } else {
        postUrl = '/{{ craft.i18n.getCurrentLocale() }}/';
    }
&lt;/script&gt;
</code></pre>

<p>Furthermore, an hidden field should be added in order to call the Sprout Forms' controller on submit:</p>

<pre><code>&lt;input type="hidden" name="action" value="sproutForms/entries/saveEntry"&gt;
</code></pre>

<p>This submits the form in the current locale, and returns errors in this same locale.</p>

CC BY-SA 3.0
2017-10-13T08:55:27.220Z
2017-10-13T08:55:27.220Z
Romain P.
<p>I'm using a form using Sprout Forms plugin. This form is set for <a href="https://sprout.barrelstrengthdesign.com/craft-plugins/forms/docs/examples/submitting-a-form-via-ajax" rel="nofollow noreferrer">submitting via AJAX</a>. The documentation explains <a href="https://sprout.barrelstrengthdesign.com/craft-plugins/forms/docs/examples/translating-error-messages" rel="nofollow noreferrer">how to translate error message</a>, but this is not working via AJAX submissions.</p>

<p>Currently, the primary language of this website is French. While the site is browsed in English or Dutch, it still shows AJAX errors in French.</p>

<p>How can I get Sprout Forms errors in current language using AJAX?</p>

<plugin-development><localization><plugin-sproutforms>
How can I get Sprout Forms errors in current language using AJAX?
# How can I get Sprout Forms errors in current language using AJAX?

(Asked by: username_0 on 2017-01-03)

I'm using a form using Sprout Forms plugin. This form is set for [submitting via AJAX](https://sprout.barrelstrengthdesign.com/craft-plugins/forms/docs/examples/submitting-a-form-via-ajax). The documentation explains [how to translate error message](https://sprout.barrelstrengthdesign.com/craft-plugins/forms/docs/examples/translating-error-messages), but this is not working via AJAX submissions.

Currently, the primary language of this website is French. While the site is browsed in English or Dutch, it still shows AJAX errors in French.

How can I get Sprout Forms errors in current language using AJAX?

**Tags:** plugin-development, localization, plugin-sproutforms

---

## 1 answers

### Answer by username_0 on 2017-10-13. Score: 2

The AJAX POST url variable (postUrl) should be set from the form template with this Twig code:


Furthermore, an hidden field should be added in order to call the Sprout Forms' controller on submit:


This submits the form in the current locale, and returns errors in this same locale.


---

