Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

http_get_preferred_language()

Description

Use the browser settings to determine the default / preferred language

Parameters

ColumnTypeDefaultDescription
$strict_mode boolean false

Return

string The language string the user may prefer

Location

include/language_functions.php lines 560 to 609

Definition

 
function http_get_preferred_language($strict_mode false)
{
    global 
$languages;

    if (empty(
$_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
        return 
null;
    }

    
$accepted_languages preg_split('/,\s*/'$_SERVER['HTTP_ACCEPT_LANGUAGE']);
    
$current_lang false;
    
$current_quality 0;
    
$language_map = array();

    foreach (
$languages as $key => $value) {
        
$language_map[strtolower($key)] = $key;
    }

    foreach (
$accepted_languages as $accepted_language) {
        
$res preg_match('/^([a-z]{1,8}(?:-[a-z]{1,8})*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$/i'$accepted_language$matches);

        if (!
$res) {
            continue;
        }

        
$lang_code explode('-'$matches[1]);

        
// Use specified quality, if any
        
if (isset($matches[2])) {
            
$lang_quality = (float)$matches[2];
        } else {
            
$lang_quality 1.0;
        }

        while (
count($lang_code)) {
            
$short strtolower(join('-'$lang_code));
            if (
array_key_exists($short$language_map) && $lang_quality $current_quality) {
                
$current_lang $language_map[$short];
                
$current_quality $lang_quality;
            }

            if (
$strict_mode) {
                break;
            }

            
array_pop($lang_code);
        }
    }

    return 
$current_lang;
}

This article was last updated 4th December 2024 08:35 Europe/London time based on the source file dated 27th November 2024 15:30 Europe/London time.