首页 文章

qTranslate X和AJAX:语言切换不检测加载Ajax的URL

提问于
浏览
0

我有WordPress theme loading pages via AJAX,要求这些页面都是英文和德文 . 我总是在这些情况下使用qTranslate,因为我可以使用我选择的语言快速手动填充内容 .

但是,qTranslate X不会读取AJAX更新的URL . Consider this example: 用户在德语的特定帖子(website.com/firstpost)上阅读,因为它是默认语言 . 用户点击另一个帖子,访问website.com/anotherpost . 在那里,用户想要用英语阅读这个"another post",所以用户点击英国国旗 . 因为website.com/anotherpost是通过AJAX加载的,所以qTranslate X将用户带到website.com/en/firstpost(或者例如:website.com/firstpost?lang=en),对于插件,URL仍然是网站 . COM / firstpost .

我希望有人有这个特定插件的经验,并且它运行AJAX调用 . 我是AJAX的新手,因为我从未使用它,所以请原谅我代表的任何愚蠢的术语和/或思考过程 .

如果您需要更多信息,请告诉我 .

1 回答

  • 0

    你需要通过ajax调用发送当前语言:

    var actioncall = {
      action: 'myajax_function',
      qtx_lang : MyAjax.qtx_lang
    };
    
    $.post(MyAjax.ajaxurl,actioncall , function(response) {
    
    // do stuff 
    
    }, 'json');
    });
    

    要做到这一点,你需要:

    global $q_config;
    wp_localize_script( 'existing_script', 'MyAjax', 
         array( 'ajaxurl' => admin_url( 'admin-ajax.php' ),
                'qtx_lang' => $q_config['language']
     ) );
    

    最后:

    在您的prefix_ajax_myajax_function()上,提取帖子,您可以像这样使用它:

    $qtx_lang= $_POST['qtx_lang'];
    ....
    $title = qtranxf_use($qtx_lang,$the_page->post_title);
    

相关问题