• On this website: https://webicius.com/SCHARC/

    I have two problems created by qTranslate:

    1) The redirect is not working: while sometimes it works at the first load of the page, going again to the same URL resets the chosen language to English.

    2) Even if the appropriate option has been switched on in the settings, it will not show /en at the end of the URL when the homepage language is automatically switched to English.

    This is the init in qTranslate:

    // detect language and forward if needed
    if($q_config[‘detect_browser_language’] && $q_config[‘url_info’][‘redirect’] && !isset($_COOKIE[‘qtrans_cookie_test’]) && $q_config[‘url_info’][‘language’] == $q_config[‘default_language’]) {
    $target = false;
    $prefered_languages = array();
    if(isset($_SERVER[“HTTP_ACCEPT_LANGUAGE”]) && preg_match_all(“#([^;,]+)(;[^,0-9]*([0-9\.]+)[^,]*)?#i”,$_SERVER[“HTTP_ACCEPT_LANGUAGE”], $matches, PREG_SET_ORDER)) {
    $priority = 1.0;
    foreach($matches as $match) {
    if(!isset($match[3])) {
    $pr = $priority;
    $priority -= 0.001;
    } else {
    $pr = floatval($match[3]);
    }
    $prefered_languages[$match[1]] = $pr;
    }
    arsort($prefered_languages, SORT_NUMERIC);
    foreach($prefered_languages as $language => $priority) {
    if(strlen($language)>2) $language = substr($language,0,2);
    if(qtrans_isEnabled($language)) {
    if($q_config[‘hide_default_language’] && $language == $q_config[‘default_language’]) break;
    $target = qtrans_convertURL(get_option(‘home’),$language);
    break;
    }
    }
    }
    $target = apply_filters(“qtranslate_language_detect_redirect”, $target);
    if($target !== false) {
    wp_redirect($target);
    exit();
    }
    }

    And this is the PHP action I tried to solve the issue with, without success:

    // detect language and forward if needed
    if($q_config[‘detect_browser_language’] && $q_config[‘url_info’][‘redirect’] && !isset($_COOKIE[‘qtrans_cookie_test’]) && $q_config[‘url_info’][‘language’] == $q_config[‘default_language’]) {
    $target = false;
    $prefered_languages = array();
    if(isset($_SERVER[“HTTP_ACCEPT_LANGUAGE”]) && preg_match_all(“#([^;,]+)(;[^,0-9]*([0-9\.]+)[^,]*)?#i”,$_SERVER[“HTTP_ACCEPT_LANGUAGE”], $matches, PREG_SET_ORDER)) {
    $priority = 1.0;
    foreach($matches as $match) {
    if(!isset($match[3])) {
    $pr = $priority;
    $priority -= 0.001;
    } else {
    $pr = floatval($match[3]);
    }
    $prefered_languages[$match[1]] = $pr;
    }
    arsort($prefered_languages, SORT_NUMERIC);
    foreach($prefered_languages as $language => $priority) {
    if(strlen($language)>2) $language = substr($language,0,2);
    if(qtrans_isEnabled($language)) {
    if($q_config[‘hide_default_language’] && $language == $q_config[‘default_language’]) break;
    $target = qtrans_convertURL(get_option(‘home’),$language);
    break;
    }
    }
    }
    $target = apply_filters(“qtranslate_language_detect_redirect”, $target);
    if($target !== false) {
    wp_redirect($target);
    exit();
    }
    }

    Do you have any idea why this may not be working?

    https://www.ads-software.com/plugins/qtranslate/

  • The topic ‘Qtranslate not redirecting according to browser language’ is closed to new replies.