This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 9 replies, has 3 voices, and was last updated by  Matthias 6 years, 1 month ago. The support staff assigned to this topic is Harshad.

Author Posts
Author Posts
April 30, 2012 at 7:23 pm #57416


I have a problem with ajax-calls. No matter what I do, all ajax-calls with admin-ajax.php return the language that I set as the admin default language. When I switch this language, also the ajax-calls switch. No matter if I'm logged in or not. I also tried this approach ( No success, so far...

Is there any way to get that?

May 1, 2012 at 5:42 am #57443


What version of WPML have you installed?

May 1, 2012 at 8:10 am #57463


Version 2.4.3 on WP 3.3.2

May 1, 2012 at 10:45 am #57476


Can you try this
1) Disable WPML plugin.
2) Delete it from the 'plugins' directory.
3) Upload again.
4) Enable.
This operation does not change any of your data.

May 1, 2012 at 3:20 pm #57504


I did that. Nothing changed except the name of the plugin... Now it's called WPML Multilingual CMS and not Sitepress anymore. But the ajax calls still don't localize.

May 2, 2012 at 8:11 am #57566


So, is there any solution for this problem? I'm working on a project that has to go online within the next days. The only thing that is not working correctly is this ajax-localization. But this is a quite heavy problem, because the Woocommerce-plugin, that relies heavily on ajax-calls, is not localized properly.
You recommended the use of this e-commerce-plugin ( and now it's not working (also this problem could not be solved so far: I'm quite disappointed at the moment.

May 2, 2012 at 8:26 am #57570


Hi Matthias,

AJAX URL should have language parameter.

For example,

$value['ajax_url'] = admin_url('admin-ajax.php?lang=' . ICL_LANGUAGE_CODE);


May 2, 2012 at 8:32 am #57572


Yes, I know. I already have this language-parameter. But all gettext-functions of my ajax-call are not localized ( __(), _e()).

May 2, 2012 at 8:41 am #57577


You can try to use before ( __(), _e() ) switch lang function, for example:

global $sitepress;

// changes language
$sitepress->switch_lang($lang, true);

__('text'), _e('text')

// changes to default

May 2, 2012 at 9:15 am #57591


Ok, thanks, now I got a solution. After switching the language with

global $sitepress;
$sitepress->switch_lang($lang, true);

I needed to load my theme-text-domain manually before calling any gettext-function like this:

load_theme_textdomain( 'mythemetextdomain', get_template_directory() . '/languages' );

I had to do the same for all the woocommerce ajax-actions. But this is a bit dirty, because I had to hack the core plugin-files. I will ask the people from woocommerce to put a hook to the beginning of their ajax-calls, so that it is possible to achieve this without hacking the core files.

Thanks for your help!

The topic ‘[Closed] Ajax call is not localized’ is closed to new replies.