Changeset 1078
- Timestamp:
- 04/23/07 13:16:47 (2 years ago)
- Files:
-
- devel/units/gettext/library.php (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
devel/units/gettext/library.php
r985 r1078 5 5 { 6 6 global $CFG; 7 7 8 8 if ($domain == 'none') 9 9 { … … 16 16 if ($i18n != null) 17 17 { 18 return $i18n->translate($text); 18 19 foreach($i18n as $language){ 20 if($language->translate($text)!=$text){ 21 return $language->translate($text); 22 } 23 } 24 return $text; 19 25 } 20 26 else … … 63 69 if (array_key_exists($USER->locale, $CFG->languages_domain_paths[$domain])) 64 70 { 65 // Double check if file exists 66 if (file_exists($CFG->languages_domain_paths[$domain][$USER->locale])) 67 { 68 $input = new CachedFileReader($CFG->languages_domain_paths[$domain][$USER->locale]); 69 $l10n[$domain][$USER->locale] = new gettext_reader($input); 70 71 return $l10n[$domain][$USER->locale]; 72 } 73 else 74 { 75 return; 76 } 77 } 78 else 79 { return; 71 rsort($CFG->languages_domain_paths[$domain][$USER->locale]); 72 foreach($CFG->languages_domain_paths[$domain][$USER->locale] as $languagedomain){ 73 // Double check if file exists 74 if (file_exists($languagedomain)){ 75 $input = new CachedFileReader($languagedomain); 76 $l10n[$domain][$USER->locale][] = new gettext_reader($input); 77 } 78 } 79 return $l10n[$domain][$USER->locale]; 80 } 81 else{ 82 return; 80 83 } 81 84 } … … 106 109 107 110 foreach ($langs as $lang) { 108 // parsing language preference instructions 111 // parsing language preference instructions 109 112 // 2_digit_code[-longer_code][;q=coefficient] 110 113 ereg('([a-z]{1,2})(-([a-z0-9]+))?(;q=([0-9\.]+))?', $lang, $found); … … 144 147 { 145 148 global $CFG, $messages; 146 149 147 150 // Load known language codes 148 151 parse_languages_available(); 149 152 150 153 // Array to hold domain files, available in $CFG->languages_installed 151 154 // E.g. $CFG->languages_installed['elgg']['nl'] = '/path/to/nl/LC_MESSAGES/elgg.mo' … … 189 192 while(false !== ($file = readdir($langdir))) 190 193 { 194 $firstchar = substr($file, 0, 1); 195 196 if ($firstchar == '.' or $file == 'CVS' or $file == '_vti_cnf' or $file == '.svn') 197 { 198 continue; 199 } 191 200 // Grab the .mo file 192 201 eregi("([a-zA-Z].*)\.mo", $file, $match); 193 194 202 if ($match) 195 203 { 196 $CFG->languages_domain_paths[$match[1]][$dir] = $root.'languages/'.$dir.'/LC_MESSAGES/'.$match[0];204 $CFG->languages_domain_paths[$match[1]][$dir][] = $root.'languages/'.$dir.'/LC_MESSAGES/'.$match[0]; 197 205 } 206 $match = null; 198 207 } 199 208 } … … 209 218 { 210 219 global $CFG; 211 220 212 221 // Only load once 213 222 if (!isset($CFG->languages_available)) … … 233 242 // Load default language path 234 243 parse_installed_languages($CFG->dirroot); 235 244 236 245 // Load plugin language paths 237 246 $plugindir = opendir($CFG->dirroot . 'mod/'); … … 249 258 } 250 259 } 251 260 252 261 // Store the browser setting 253 262 $USER->languages_browser = parse_http_accept_language(); … … 257 266 { 258 267 $bad = $CFG->defaultlocale; 259 268 260 269 // Empty it, and send a message to the screen 261 270 $CFG->defaultlocale = ''; 262 271 263 272 global $messages; 264 273 265 274 $messages[] = "Unknown language code: ".$bad.". Please ask the system administrator to properly configure \$CFG->defaultlocale in the main configuration file."; 266 275 } 267 276 268 277 // Setup variables to hold the user language 269 278 $USER->locale = $CFG->defaultlocale; … … 278 287 279 288 280 // logged_on is not yet defined yet in this stage, 281 // use USER->ident for this... 289 // logged_on is not yet defined yet in this stage, 290 // use USER->ident for this... 282 291 // TODO Implement better check! 283 292 if ($USER->ident != 0) … … 305 314 { 306 315 $keys = array_keys($USER->languages_browser); 307 316 308 317 if ($browser = $USER->languages_browser[$keys[0]]) 309 318 { … … 316 325 $setting = $CFG->defaultlocale; 317 326 } 318 327 319 328 // Store the value 320 329 $flag = new StdClass; … … 331 340 { 332 341 // User is logged out 333 342 334 343 // TODO special actions? For now language will be set 335 344 // to $CFG-defaultlocale for non logged in users or via … … 374 383 { 375 384 // Have to replicate flag setting because of including order 376 385 377 386 // unset first 378 387 delete_records('user_flags','flag','language','user_id',$USER->ident); … … 396 405 // from Elgg locales 397 406 $time_locale = $USER->locale; 398 407 399 408 if (!substr($USER->locale, 2, 1) == "_") { 400 409 $time_locale = $USER->locale . "_" . strtoupper($USER->locale); … … 413 422 $body = <<< END 414 423 <h2>$title</h2> 415 <p>$blurb</p> 424 <p>$blurb</p> 416 425 END; 417 426 … … 427 436 $tmp .= '<select name="lang">'; 428 437 $tmp .= '<option value="default">'.__gettext('default')."</option>\n"; 429 438 430 439 ksort($CFG->languages_installed); 431 440 432 441 foreach ($CFG->languages_installed as $key => $description) 433 442 { … … 439 448 $tmp .= '<option value="'.$key.'" '.$selected.'>'.$description."</option>\n"; 440 449 } 441 450 442 451 $tmp .= '</select>'; 443 452 } … … 456 465 { 457 466 global $CFG, $USER, $messages; 458 467 459 468 $action = optional_param('action'); 460 469 $id = optional_param('id',0,PARAM_INT);
