I’m using WooCommerce for a site that I’m currently working on. And I’m creating it for a language other than English. I do the translations by means of the .po
file.
The issue that I’m encountering is in the Checkout page. There is a table of order review which upon page loaded seems to be refreshed by means of AJAX call. Before the call the texts are all translated. But after the call the texts all reverted back to their original language (ie. English).
How do I retain the translation after the AJAX call?
I think I fixed the issue with the following extended function in my plugin:
It will check if an AJAX call was made. If the call was coming from the frontend, it checks for a
lang
request param. If one could be found, it set’s the$locale
to this value. Otherwise it doesn’t changes the locale to be backend setting, so it should be the locale from the frontend, defined in thewp-config.php
file.Please update to version 2.1 of the plugin and check again.
Thanks again for @Rarst and @cybnet for their hints.
You have differents languages in your site, although your frontend is not multilingual, you serve one language in frontend and another in backend. Ajax in WordPress is processed in the “admin area” (wp-admin/admin-ajax.php), so the reponse of an ajax request will be in the language defined in the admin area. “English” in your case.
I don’t know exactly how the plugin “Backend localization” works but other plugins that affect to the language need a language parameter in the ajax request. For example, to make qTranslate working in ajax, the lang param has to be added to the ajaxurl value in the javascript, something like
ajaxurl+'?lang=es'
. You will need to contact to developer of “Backend localization”Another possible fix is to add:
at line 11 in an override version of
review-order.php
, which should be copied from:to: