Changeset 1021
- Timestamp:
- 04/24/06 16:44:17 (7 years ago)
- Location:
- trunk/wifidog-auth
- Files:
-
- 7 modified
-
CHANGELOG (modified) (1 diff)
-
wifidog/classes/Locale.php (modified) (4 diffs)
-
wifidog/classes/LocaleList.php (modified) (1 diff)
-
wifidog/classes/Style.php (modified) (1 diff)
-
wifidog/classes/User.php (modified) (1 diff)
-
wifidog/config.php (modified) (2 diffs)
-
wifidog/include/language.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wifidog-auth/CHANGELOG
r1020 r1021 1 2006-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 1 6 2006-04-24 Benoit Grégoire <bock@step.polymtl.ca> 2 7 * 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 128 128 $object = null; 129 129 $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/>"; 130 131 131 132 /* Try to guess the lang */ … … 137 138 if (empty ($locale_id)) { 138 139 $object = self :: getObject(DEFAULT_LANG); 139 self :: setCurrentLocale($object);140 140 } else { 141 141 $object = self :: getObject($locale_id); 142 self :: setCurrentLocale($object);143 142 } 144 143 … … 213 212 } 214 213 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.) 218 215 * @return boolean true on success, false on failure. 219 216 */ 220 217 public static function setCurrentLocale($locale) { 221 218 global $session; 219 global $AVAIL_LOCALE_ARRAY; 222 220 $retval = false; 223 221 224 222 // Get new locale ID, assume default if null 225 223 if ($locale != null) { 226 224 $locale_id = $locale->getId(); 227 $session->set(SESS_LANGUAGE_VAR, $locale_id);228 225 $retval = true; 229 $q = "par m";226 $q = "parameter"; 230 227 } else { 231 228 $locale_id = DEFAULT_LANG; 232 $session->set(SESS_LANGUAGE_VAR, $locale_id);233 229 $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/>"; 236 234 237 235 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 } 238 241 // 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/>"; 240 250 241 251 // 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/>"; 244 254 $retval = false; 245 255 } else { … … 248 258 textDomain('messages'); 249 259 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); 253 262 $retval = true; 254 263 } 255 264 } 256 257 265 return $retval; 258 266 } -
trunk/wifidog-auth/wifidog/classes/LocaleList.php
r1013 r1021 131 131 $locale = $user->getPreferedLocale(); 132 132 } else { 133 $locale = $session->get( 'SESS_LANGUAGE_VAR');133 $locale = $session->get(SESS_LANGUAGE_VAR); 134 134 135 135 if (empty ($locale)) { -
trunk/wifidog-auth/wifidog/classes/Style.php
r1013 r1021 68 68 { 69 69 function Style() { 70 $session = new Session();71 if (!empty($_REQUEST['lang']))72 {73 $session->set('SESS_LANGUAGE_VAR', $_REQUEST['lang']);74 }75 70 76 if ($session->get('SESS_LANGUAGE_VAR')) {77 setlocale(LC_ALL, $session->get('SESS_LANGUAGE_VAR'));78 }79 71 } 80 72 -
trunk/wifidog-auth/wifidog/classes/User.php
r1018 r1021 371 371 $locale = $this->mRow['prefered_locale']; 372 372 if (empty($locale) && !empty($session)) 373 $locale = $session->get( 'SESS_LANGUAGE_VAR');373 $locale = $session->get(SESS_LANGUAGE_VAR); 374 374 if (empty($locale)) 375 375 $locale = DEFAULT_LANG; -
trunk/wifidog-auth/wifidog/config.php
r1020 r1021 169 169 global $AVAIL_LOCALE_ARRAY; 170 170 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'); 191 189 192 190 /** … … 194 192 * ================ 195 193 * 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 */ 198 define('DEFAULT_LANG', 'fr_CA'); 204 199 205 200 /********************************************************************\ -
trunk/wifidog-auth/wifidog/include/language.php
r916 r1021 48 48 49 49 if (!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']); 51 53 } 52 54 53 55 $locale = Locale::getCurrentLocale(); 56 Locale::setCurrentLocale($locale); 54 57 $locale_id = $locale->getId(); 55 58
