Пример #1
0
function qtranxf_http_negotiate_language()
{
    global $q_config;
    if (function_exists('http_negotiate_language')) {
        $default_language = $q_config['default_language'];
        $supported = array();
        $supported[] = qtranxf_html_locale($q_config['locale'][$default_language]);
        //needs to be the first
        if (!empty($q_config['locale_html'][$default_language])) {
            $supported[] = $q_config['locale_html'][$default_language];
        }
        foreach ($q_config['enabled_languages'] as $lang) {
            if ($lang == $default_language) {
                continue;
            }
            $supported[] = qtranxf_html_locale($q_config['locale'][$lang]);
            if (!empty($q_config['locale_html'][$lang])) {
                $supported[] = $q_config['locale_html'][$lang];
            }
        }
        $fallback = array();
        $locale_negotiated = http_negotiate_language($supported, $fallback);
        if ($fallback == NULL) {
            $locale_negotiated = 'en';
        }
        return qtranxf_match_language_locale($locale_negotiated);
    } else {
        return qtranxf_get_browser_language();
    }
}
Пример #2
0
function qtranxf_http_negotiate_language()
{
    global $q_config;
    if (function_exists('http_negotiate_language')) {
        $supported = array();
        $supported[] = str_replace('_', '-', $q_config['locale'][$q_config['default_language']]);
        //needs to be the first
        foreach ($q_config['enabled_languages'] as $lang) {
            if ($lang == $q_config['default_language']) {
                continue;
            }
            $supported[] = str_replace('_', '-', $q_config['locale'][$lang]);
        }
        $locale_negotiated = http_negotiate_language($supported);
        //since 3.2-b3 added search, since locale may be different from two-letter code and not even started with language code.
        foreach ($q_config['enabled_languages'] as $lang) {
            $locale = str_replace('_', '-', $q_config['locale'][$lang]);
            if ($locale == $locale_negotiated) {
                return $lang;
            }
        }
    } else {
        return qtranxf_get_browser_language();
    }
    return null;
}