Changeset 1078

Show
Ignore:
Timestamp:
04/23/07 13:16:47 (2 years ago)
Author:
ben
Message:

gettext change by Diego Ramirez; plugins can now supply their own translations.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/units/gettext/library.php

    r985 r1078  
    55    { 
    66        global $CFG; 
    7          
     7 
    88        if ($domain == 'none') 
    99        { 
     
    1616        if ($i18n != null) 
    1717        { 
    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; 
    1925        } 
    2026        else 
     
    6369            if (array_key_exists($USER->locale, $CFG->languages_domain_paths[$domain])) 
    6470            { 
    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; 
    8083            } 
    8184        } 
     
    106109 
    107110        foreach ($langs as $lang) { 
    108             // parsing language preference instructions  
     111            // parsing language preference instructions 
    109112            // 2_digit_code[-longer_code][;q=coefficient] 
    110113            ereg('([a-z]{1,2})(-([a-z0-9]+))?(;q=([0-9\.]+))?', $lang, $found); 
     
    144147    { 
    145148        global $CFG, $messages; 
    146          
     149 
    147150        // Load known language codes 
    148151        parse_languages_available(); 
    149          
     152 
    150153        // Array to hold domain files, available in $CFG->languages_installed 
    151154        // E.g. $CFG->languages_installed['elgg']['nl'] = '/path/to/nl/LC_MESSAGES/elgg.mo' 
     
    189192                while(false !== ($file = readdir($langdir))) 
    190193                { 
     194                  $firstchar = substr($file, 0, 1); 
     195 
     196                  if ($firstchar == '.' or $file == 'CVS' or $file == '_vti_cnf' or $file == '.svn') 
     197                  { 
     198                      continue; 
     199                  } 
    191200                    // Grab the .mo file 
    192201                    eregi("([a-zA-Z].*)\.mo", $file, $match); 
    193                      
    194202                    if ($match) 
    195203                    { 
    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]; 
    197205                    } 
     206                    $match = null; 
    198207                } 
    199208            } 
     
    209218    { 
    210219        global $CFG; 
    211          
     220 
    212221        // Only load once 
    213222        if (!isset($CFG->languages_available)) 
     
    233242        // Load default language path 
    234243        parse_installed_languages($CFG->dirroot); 
    235          
     244 
    236245        // Load plugin language paths 
    237246        $plugindir = opendir($CFG->dirroot . 'mod/'); 
     
    249258            } 
    250259        } 
    251          
     260 
    252261        // Store the browser setting 
    253262        $USER->languages_browser = parse_http_accept_language(); 
     
    257266        { 
    258267            $bad = $CFG->defaultlocale; 
    259              
     268 
    260269            // Empty it, and send a message to the screen 
    261270            $CFG->defaultlocale = ''; 
    262              
     271 
    263272            global $messages; 
    264              
     273 
    265274            $messages[] = "Unknown language code: ".$bad.". Please ask the system administrator to properly configure \$CFG->defaultlocale in the main configuration file."; 
    266275        } 
    267          
     276 
    268277        // Setup variables to hold the user language 
    269278        $USER->locale = $CFG->defaultlocale; 
     
    278287 
    279288 
    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... 
    282291        // TODO Implement better check! 
    283292        if ($USER->ident != 0) 
     
    305314                { 
    306315                    $keys = array_keys($USER->languages_browser); 
    307                      
     316 
    308317                    if ($browser = $USER->languages_browser[$keys[0]]) 
    309318                    { 
     
    316325                    $setting = $CFG->defaultlocale; 
    317326                } 
    318                  
     327 
    319328                // Store the value 
    320329                $flag = new StdClass; 
     
    331340        { 
    332341            // User is logged out 
    333              
     342 
    334343            // TODO special actions? For now language will be set 
    335344            // to $CFG-defaultlocale for non logged in users or via 
     
    374383            { 
    375384                // Have to replicate flag setting because of including order 
    376                  
     385 
    377386                // unset first 
    378387                delete_records('user_flags','flag','language','user_id',$USER->ident); 
     
    396405        // from Elgg locales 
    397406        $time_locale = $USER->locale; 
    398          
     407 
    399408        if (!substr($USER->locale, 2, 1) == "_") { 
    400409            $time_locale = $USER->locale . "_" . strtoupper($USER->locale); 
     
    413422        $body = <<< END 
    414423            <h2>$title</h2> 
    415             <p>$blurb</p>     
     424            <p>$blurb</p> 
    416425END; 
    417426 
     
    427436            $tmp .= '<select name="lang">'; 
    428437            $tmp .= '<option value="default">'.__gettext('default')."</option>\n"; 
    429              
     438 
    430439            ksort($CFG->languages_installed); 
    431              
     440 
    432441            foreach ($CFG->languages_installed as $key => $description) 
    433442            { 
     
    439448                $tmp .= '<option value="'.$key.'" '.$selected.'>'.$description."</option>\n"; 
    440449            } 
    441              
     450 
    442451            $tmp .= '</select>'; 
    443452        } 
     
    456465    { 
    457466        global $CFG, $USER, $messages; 
    458          
     467 
    459468        $action = optional_param('action'); 
    460469        $id = optional_param('id',0,PARAM_INT);