Calls to __() in an AJAX function are not translated even after I set the lang parameter in the AJAX URL.

It appears that Sitepress is not detecting the lang parameter properly.

I’ve found a workaround, but it seems cumbersome.

global $sitepress;
$sitepress->switch_lang($_REQUEST[‘lang’], true);

load_theme_textdomain( ‘mytextdomain’, get_template_directory() . ‘/languages’ );

Read more here: WPML admin-ajax.php call not localized after setting lang


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: