Hi, Amit here, I am the WPML Support Manager, our current ticket queue is quite calm and I'd like to encourage you to use our new chat support option

We are working hard to debug and look at every single report

All of the known issues are documented in https://wpml.org/known-issues/ you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described here https://wpml.org/faq/checklist-before-opening-a-ticket-in-wpml-support/

in WPML we are very proud at our level of support, we are one team from all over the world and we are all experienced WordPress developers, you can read more about us here - https://wpml.org/forums/supporters/

OK enough talking, going to fix some issues

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 3 replies, has 3 voices.

Last updated by christianc-8 5 years, 3 months ago.

Assigned support staff: Amit.

Author Posts
August 23, 2013 at 9:51 am #157082

Fabien

There are a number of forum thread to point the fact that ajax calls are not localized.
http://wpml.org/forums/topic/problems-with-ajax/
http://wpml.org/forums/topic/ajax-call-is-not-localized/
http://wpml.org/forums/topic/switch_lang-and-load_textdomain-does-not-work-in-ajax-request/
http://wpml.org/forums/topic/back-to-default-language-after-ajax-request/

The issue described on those thread are about different plugins, but one fact is common : during ajax calls, WordPress language is not set correctly, even if the "lang" parameter is present in the request.

The issue comes from the fact that WPML does not set the locale on the admin side, and ajax calls are considered by WordPress as admin (ajax calls url is /wp-admin/admin-ajax.php.

Here is a simple code that can fix this issue for all ajax calls for all plugins. You can put this code in a new plugin to avoid modifying WPML code code.

add_action('plugins_loaded', 'wpml_fix_ajax_install');
function wpml_fix_ajax_install(){
    global $sitepress;
    if(defined('DOING_AJAX') && DOING_AJAX && isset($_REQUEST['action']) && isset($_REQUEST['lang']) ){
        // remove WPML legacy filter, as it is not doing its job for ajax calls
        remove_filter('locale', array($sitepress, 'locale'));
        add_filter('locale', 'wpml_ajax_fix_locale');
        function wpml_ajax_fix_locale($locale){
            global $sitepress;
            // simply return the locale corresponding to the "lang" parameter in the request
            return $sitepress->get_locale($_REQUEST['lang']);
        }
    }
}
August 23, 2013 at 11:24 am #157130

Amit
Supporter

Hi Christophe,

Thanks! I am passing that information to the development team to take a look it.

Cheers!

August 23, 2013 at 11:30 am #157131

Amit
Supporter

I am actually closing that, any other issues please let us know!

January 18, 2016 at 11:27 am #790027

christianc-8

Hi. I had the same issue, I tried the solution suggested by Fabien, and it seems to work apart from the fact that the language switcher brings to the homepage url in the correct language, not to the translated page. Any newer fix for ajax problems? Thanks.