Example #1
0
function qtranxf_detect_admin_language($url_info)
{
    global $q_config;
    $cs = null;
    $lang = null;
    /** @since 3.2.9.9.6
     * Detect language from $_POST['WPLANG'].
     */
    if (isset($_POST['WPLANG'])) {
        // User is switching the language using "Site Language" field on page /wp-admin/options-general.php
        $wplang = sanitize_text_field($_POST['WPLANG']);
        if (empty($wplang)) {
            $wplang = 'en';
        }
        foreach ($q_config['enabled_languages'] as $language) {
            if ($q_config['locale'][$language] != $wplang) {
                continue;
            }
            $lang = $language;
            break;
        }
        if (!$lang) {
            $lang = substr($wplang, 0, 2);
            $lang = qtranxf_resolveLangCase($lang, $cs);
        }
    }
    if (!$lang && isset($_COOKIE[QTX_COOKIE_NAME_ADMIN])) {
        $lang = qtranxf_resolveLangCase($_COOKIE[QTX_COOKIE_NAME_ADMIN], $cs);
        $url_info['lang_cookie_admin'] = $lang;
    }
    if (!$lang) {
        //$locale = get_locale();
        //$url_info['locale'] = $locale;
        //$lang = qtranxf_resolveLangCase(substr($locale,0,2),$cs);
        //$url_info['lang_locale'] = $lang;
        //if(!$lang)
        $lang = $q_config['default_language'];
    }
    $url_info['doing_front_end'] = false;
    $url_info['lang_admin'] = $lang;
    return $url_info;
}
Example #2
0
function qtranxf_detect_language_front(&$url_info)
{
    global $q_config;
    //assert($url_info['doing_front_end']);
    while (true) {
        if (isset($_COOKIE[QTX_COOKIE_NAME_FRONT])) {
            $cs = null;
            $lang = qtranxf_resolveLangCase($_COOKIE[QTX_COOKIE_NAME_FRONT], $cs);
            $url_info['lang_cookie_front'] = $lang;
            if ($lang) {
                break;
            }
        }
        if ($q_config['detect_browser_language'] && (!isset($_SERVER['HTTP_REFERER']) || strpos($_SERVER['HTTP_REFERER'], $url_info['host']) === FALSE) && (empty($url_info['wp-path']) || $url_info['wp-path'] == '/')) {
            $lang = qtranxf_http_negotiate_language();
            $url_info['lang_browser'] = $lang;
            if ($lang) {
                break;
            }
        }
        $lang = $q_config['default_language'];
        break;
    }
    if (!isset($url_info['doredirect']) && (!$q_config['hide_default_language'] || $lang != $q_config['default_language'])) {
        $url_info['doredirect'] = 'language needs to be shown in url';
    }
    return $lang;
}