Changeset 1021

Show
Ignore:
Timestamp:
04/24/06 16:44:17 (7 years ago)
Author:
benoitg
Message:

* Major system locale handling overhaull. Hopefully abstract out the UTF8 problems once and for all,

allowing everyone to define them the same way. Fix a few bugs along the way.
Should also be a little faster.

Location:
trunk/wifidog-auth
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/CHANGELOG

    r1020 r1021  
     12006-04-24 Benoit Grégoire  <bock@step.polymtl.ca> 
     2        * Major locale handling changes.  Hopefully abstract out the UTF8 problems once and for all,  
     3        allowing everyone to define them the same way.  Fix a few bugs along the way.   
     4        Should also be a little faster. 
     5 
    162006-04-24 Benoit Grégoire  <bock@step.polymtl.ca> 
    27        * Revert Rob's SYSTEM_PATH change.  Sorry about that.  The devs spent hours to finally get the PATH 
  • trunk/wifidog-auth/wifidog/classes/Locale.php

    r1013 r1021  
    128128        $object = null; 
    129129        $locale_id = $session->get(SESS_LANGUAGE_VAR); 
     130        //echo sprintf("Debug in /classes/Locale.php getCurrentLocale(): session->get(SESS_LANGUAGE_VAR)=%s", $session->get(SESS_LANGUAGE_VAR))."<br/>"; 
    130131 
    131132        /* Try to guess the lang */ 
     
    137138        if (empty ($locale_id)) { 
    138139            $object = self :: getObject(DEFAULT_LANG); 
    139             self :: setCurrentLocale($object); 
    140140        } else { 
    141141            $object = self :: getObject($locale_id); 
    142             self :: setCurrentLocale($object); 
    143142        } 
    144143 
     
    213212        } 
    214213 
    215     /** 
    216      * @todo Don't trust the value in the cookie, verify that the value is in 
    217      * the AVAILABLE locales set in the config. 
     214    /** Initialise the system locale (gettext, setlocale, etc.) 
    218215     * @return boolean true on success, false on failure. 
    219216     */ 
    220217    public static function setCurrentLocale($locale) { 
    221218        global $session; 
     219         global $AVAIL_LOCALE_ARRAY; 
    222220        $retval = false; 
    223  
     221  
    224222        // Get new locale ID, assume default if null 
    225223        if ($locale != null) { 
    226224            $locale_id = $locale->getId(); 
    227             $session->set(SESS_LANGUAGE_VAR, $locale_id); 
    228225            $retval = true; 
    229             $q = "parm"; 
     226            $q = "parameter"; 
    230227        } else { 
    231228            $locale_id = DEFAULT_LANG; 
    232             $session->set(SESS_LANGUAGE_VAR, $locale_id); 
    233229            $retval = false; 
    234             $q = "dflt"; 
    235         } 
     230            $q = "default"; 
     231        } 
     232        //pretty_print_r($locale); 
     233        //echo sprintf("Debug in /classes/Locale.php setCurentLocale(): locale_id=%s", $locale_id)."<br/>"; 
    236234 
    237235        if (GETTEXT_AVAILABLE) { 
     236            $lang_only_locale_id = substr ($locale_id, 0 , 2); 
     237                   if(!isset($AVAIL_LOCALE_ARRAY[$locale_id]) && !isset($AVAIL_LOCALE_ARRAY[$lang_only_locale_id])) 
     238                   { 
     239                     echo srintf("Warning in /classes/Locale.php setCurentLocale: Neither %s or %s are available in AVAIL_LOCALE_ARRAY", $locale_id, $lang_only_locale_id)."<br/>"; 
     240                   } 
    238241            // Try to set locale 
    239             $current_locale = setlocale(LC_ALL, $locale_id); 
     242            $candidate_locale_array[] = str_ireplace('.UTF8', '', $locale_id).'.UTF-8'; 
     243            $candidate_locale_array[] = str_ireplace('.UTF8', '', $locale_id); 
     244            $candidate_locale_array[] = $lang_only_locale_id.'.UTF-8'; 
     245            $candidate_locale_array[] = $lang_only_locale_id; 
     246 
     247              
     248            $current_locale = setlocale(LC_ALL, $candidate_locale_array); 
     249               //echo sprintf("Warning in /classes/Locale.php setCurentLocale: Unable to setlocale() to %s: %s.  I tried %s, %s, %s, %s, and got return value: %s, current locale is: %s",$q, $locale_id, $candidate_locale_array[0], $candidate_locale_array[1], $candidate_locale_array[2], $candidate_locale_array[3], $current_locale, setlocale(LC_ALL, 0))."<br/>"; 
    240250 
    241251            // Test it against current PHP locale 
    242             if ($current_locale != $locale_id) { 
    243                 echo "Warning in /classes/Locale.php setCurentLocale: Unable to setlocale() to ".$q.":".$locale_id.", return value: $current_locale, current locale: ".setlocale(LC_ALL, 0)."<br/>"; 
     252            if (substr ($current_locale, 0 , 2) != $lang_only_locale_id) { 
     253                echo sprintf("Warning in /classes/Locale.php setCurentLocale: Unable to setlocale() to %s: %s.  I tried %s, %s, %s, %s, and got return value: %s, current locale is: %s",$q, $locale_id, $candidate_locale_array[0], $candidate_locale_array[1], $candidate_locale_array[2], $candidate_locale_array[3], $current_locale, setlocale(LC_ALL, 0))."<br/>"; 
    244254                $retval = false; 
    245255            } else { 
     
    248258                textDomain('messages'); 
    249259 
    250                 putenv("LC_ALL=".$locale_id); 
    251                 putenv("LANGUAGE=".$locale_id); 
    252                 $session->set(SESS_LANGUAGE_VAR, $locale_id); 
     260                putenv("LC_ALL=".$current_locale); 
     261                putenv("LANGUAGE=".$current_locale); 
    253262                $retval = true; 
    254263            } 
    255264        } 
    256  
    257265        return $retval; 
    258266    } 
  • trunk/wifidog-auth/wifidog/classes/LocaleList.php

    r1013 r1021  
    131131            $locale = $user->getPreferedLocale(); 
    132132        } else { 
    133             $locale = $session->get('SESS_LANGUAGE_VAR'); 
     133            $locale = $session->get(SESS_LANGUAGE_VAR); 
    134134 
    135135            if (empty ($locale)) { 
  • trunk/wifidog-auth/wifidog/classes/Style.php

    r1013 r1021  
    6868{ 
    6969  function Style() { 
    70     $session = new Session(); 
    71     if (!empty($_REQUEST['lang'])) 
    72       { 
    73         $session->set('SESS_LANGUAGE_VAR', $_REQUEST['lang']); 
    74       } 
    7570 
    76     if ($session->get('SESS_LANGUAGE_VAR')) { 
    77         setlocale(LC_ALL, $session->get('SESS_LANGUAGE_VAR')); 
    78     } 
    7971  } 
    8072 
  • trunk/wifidog-auth/wifidog/classes/User.php

    r1018 r1021  
    371371      $locale = $this->mRow['prefered_locale']; 
    372372      if (empty($locale) && !empty($session)) 
    373         $locale = $session->get('SESS_LANGUAGE_VAR'); 
     373        $locale = $session->get(SESS_LANGUAGE_VAR); 
    374374      if (empty($locale)) 
    375375        $locale = DEFAULT_LANG; 
  • trunk/wifidog-auth/wifidog/config.php

    r1020 r1021  
    169169global $AVAIL_LOCALE_ARRAY; 
    170170 
    171 /*$AVAIL_LOCALE_ARRAY = array('fr' => 'Français', 
    172                             'en' => 'English', 
    173                             'de' => 'Deutsch', 
    174                             'pt' => 'Português'); 
    175 */ 
    176 /** 
    177  * A lot of linux distributions (Debian, BSD and Mac OS X) use locales like this: 
    178  */ 
    179 //$AVAIL_LOCALE_ARRAY = array('fr_CA' => 'Français', 
    180 //                            'en_US' => 'English', 
    181 //                            'de_DE' => 'Deutsch', 
    182 //                            'pt_PT' => 'Português'); 
    183  
    184 /** 
    185  * Other linux distributions (Ubuntu, Mandriva 10.1) use locales like this: 
    186  */ 
    187 $AVAIL_LOCALE_ARRAY = array('fr_CA.UTF8' => 'Français', 
    188                             'en_US.UTF8' => 'English', 
    189                             'de_DE.UTF8' => 'Deutsch', 
    190                             'pt_PT.UTF8' => 'Português'); 
     171 
     172/** 
     173 * Array of available languages for the user.  Each entry must have: 
     174 * -The language code (the part before the _) be present in wifidog/locales 
     175 * -Have the entire locale available in your system locale 
     176 * OR 
     177 * -Have a system locale available with only the language (ex: an en locale). 
     178 * Note that if you specify en_UK and en_US, and have only en available the 
     179 * system will NOT warn you that both will have identical results. 
     180 * Note that even if your system uses locales like fr_CA.UTF8, you do not need 
     181 * to change this, ifidog will translate for you. 
     182 * @TODO:  Setting an array of only one entry should disable the language select 
     183 * box. 
     184 */ 
     185$AVAIL_LOCALE_ARRAY = array('fr_CA' => 'Français', 
     186                            'en_US' => 'English', 
     187                            'de_DE' => 'Deutsch', 
     188                            'pt_PT' => 'Português'); 
    191189 
    192190/** 
     
    194192 * ================ 
    195193 * 
    196  * Define the default language of the WiFiDOG auth server. 
    197  * 
    198  * Remember to change this value to a valid locale, i.e.: 
    199  * - fr 
    200  * - fr_CA 
    201  * - fr_CA.UTF8 
    202  */ 
    203 define('DEFAULT_LANG', 'fr_CA.UTF8'); 
     194 * Define the default language of the WiFiDOG auth server.  The language code 
     195 * (the part before the _) must be part of the array above (the country 
     196 * subcode may differ, and should be set to your country subcode) 
     197 */ 
     198define('DEFAULT_LANG', 'fr_CA'); 
    204199 
    205200/********************************************************************\ 
  • trunk/wifidog-auth/wifidog/include/language.php

    r916 r1021  
    4848 
    4949if (!empty ($_REQUEST['wifidog_language'])) { 
    50     Locale::setCurrentLocale(Locale::getObject($_REQUEST['wifidog_language'])); 
     50     
     51            //echo "Setting to $_REQUEST[wifidog_language]<br/>"; 
     52        $session->set(SESS_LANGUAGE_VAR, $_REQUEST['wifidog_language']); 
    5153} 
    5254 
    5355$locale = Locale::getCurrentLocale(); 
     56Locale::setCurrentLocale($locale); 
    5457$locale_id = $locale->getId(); 
    5558