Changeset 434

Show
Ignore:
Timestamp:
05/06/07 19:42:38 (2 years ago)
Author:
laurentj
Message:

improved automatic detection in autolocale plugin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jelix-plugins/autolocale/autolocale.plugin.php

    r363 r434  
    3737        if($this->config['enableUrlDetection']){ 
    3838            $l = $gJCoord->request->getParam($this->config['urlParamNameLanguage']); 
    39             if($l !==null && in_array($l, $availableLang)){ 
    40                 $langDetected=true; 
    41                 $lang=$l; 
     39            if($l !==null){ 
     40                if(strpos('_',$l) ===false){ 
     41                    $lg = strtolower($l).'_'.strtoupper($l); 
     42                    if(in_array($lg, $availableLang)){ 
     43                        $langDetected=true; 
     44                        $lang=$lg; 
     45                    }else{ 
     46                        foreach($availableLang as $alang){ 
     47                            if(strpos($alang, $l) === 0){ 
     48                                $lang = $alang; 
     49                                $langDetected=true; 
     50                                break; 
     51                            } 
     52                        } 
     53                    } 
     54                }elseif(in_array($l, $availableLang)){ 
     55                    $langDetected=true; 
     56                    $lang=$l; 
     57                } 
    4258            } 
    4359        } 
     
    5167                    // pour les user-agents qui livrent un code internationnal 
    5268                    if(preg_match("/^([a-zA-Z]{2})(?:[-_]([a-zA-Z]{2}))?(;q=[0-9]\\.[0-9])?$/",$bl,$match)){ 
     69                        $match[1] = strtolower($match[1]); 
    5370                        if(isset($match[2])) 
    5471                            $l=$match[1].'_'.strtoupper($match[2]); 
     
    5875                            $lang= $l; 
    5976                            break; 
    60                         } 
    61  
    62                     // pour les user agent qui indique le nom en entier 
    63                     }elseif(preg_match("/^([a-zA-Z ]+)(;q=[0-9]\\.[0-9])?$/",$bl,$match)){ 
    64                         $langs = array('french'=>'fr_FR', 'english'=>'en_US'); 
    65                         if(isset($langs[$match[1]])){ 
    66                             $lang= $langs[$match[1]]; 
    67                             break; 
     77                        }else{ 
     78                            // try to find a similary supported language 
     79                            foreach($availableLang as $alang){ 
     80                                if(strpos($alang, $match[1]) === 0){ 
     81                                    $lang = $alang; 
     82                                    break; 
     83                                } 
     84                            } 
     85                            if($lang !='') 
     86                                break; 
    6887                        } 
    6988                    } 
Download in other formats: Unified Diff Zip Archive