예제 #1
0
 function updateFiles()
 {
     $dir = $this->path . $this->name . '/';
     $langfiles = mosReadDirectory($dir, '.po$');
     set_time_limit(60);
     foreach ($langfiles as $lf) {
         $domain = substr($lf, 0, -3);
         $catalog = new PHPGettext_Catalog($domain, $this->path);
         $catalog->setproperty('lang', $this->name);
         $catalog->setproperty('mode', _MODE_PO_);
         $catalog->load();
         $file['filename'] = "language/" . $this->name . '/' . $lf;
         $file['domain'] = $domain;
         $file['strings'] = count($catalog->strings);
         $file['percent'] = '';
         $file['translated'] = 0;
         $file['fuzzy'] = 0;
         $file['filetype'] = 'po';
         $pluralfuzz = false;
         foreach ($catalog->strings as $msg) {
             if (is_array($msg->msgstr)) {
                 foreach ($msg->msgstr as $i) {
                     $unt = empty($i);
                 }
                 if (!$unt) {
                     $file['translated']++;
                 }
             }
             if (!is_array($msg->msgstr) && !empty($msg->msgstr) && !$msg->is_fuzzy) {
                 $file['translated']++;
             }
             if ($msg->is_fuzzy) {
                 $file['fuzzy']++;
             }
         }
         $nonfuzzy = $file['strings'] - $file['fuzzy'];
         if (!$nonfuzzy) {
             $nonfuzzy = 1;
         }
         $file['percent'] = round($file['translated'] * 100 / $nonfuzzy, 2);
         unset($nonfuzzy);
         $this->files[] = $file;
     }
     $this->files[] = array('filename' => "language/" . $this->name . '.xml', 'domain' => "", 'strings' => "", 'percent' => "", 'translated' => 0, 'fuzzy' => 0, 'filetype' => 'xml');
     $langfiles = mosReadDirectory($dir . 'LC_MESSAGES/', '.mo$');
     set_time_limit(60);
     foreach ($langfiles as $lf) {
         $this->files[] = array('filename' => "language/" . $this->name . '/LC_MESSAGES/' . $lf, 'domain' => "", 'strings' => "", 'percent' => "", 'translated' => 0, 'fuzzy' => 0, 'filetype' => 'mo');
     }
     if (file_exists($this->path . '/glossary/' . $this->name . "." . $this->charset . ".po")) {
         $this->files[] = array('filename' => "language/glossary/" . $this->name . "." . $this->charset . ".po", 'domain' => "", 'strings' => "", 'percent' => "", 'translated' => 0, 'fuzzy' => 0, 'filetype' => 'gl');
     }
 }
예제 #2
0
 function scan_xml($domain, $path, $scandirs, $language = 'untranslated')
 {
     $catalog = new PHPGettext_Catalog($domain, $path);
     $catalog->setproperty('mode', _MODE_POT_);
     $catalog->setproperty('lang', $language);
     $catalog->load();
     $xml_sources = array();
     if (is_array($scandirs)) {
         foreach ($scandirs as $subdir) {
             $xml_sources = array_merge($xml_sources, $this->read_dir($subdir, 'xml', true));
         }
     } else {
         $xml_sources = $this->read_dir($scandirs, 'xml', true);
     }
     if (count($xml_sources) > 0) {
         $strings = array();
         foreach ($xml_sources as $file) {
             $p = xml_parser_create();
             xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0);
             xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
             xml_parse_into_struct($p, file_get_contents(mamboCore::get('rootPath') . '/' . $file), $values);
             xml_parser_free($p);
             foreach ($values as $key => $value) {
                 switch ($value['tag']) {
                     case 'name':
                     case 'description':
                     case 'option':
                     case 'menu':
                         if (isset($value['value']) && strlen($value['value']) >= 1) {
                             $strings[$file][] = addcslashes($value['value'], '"');
                         }
                         break;
                     case 'param':
                         if (isset($value['attributes']) && $value['attributes']['type'] != 'spacer') {
                             if (isset($value['attributes']['label'])) {
                                 $strings[$file][] = addcslashes($value['attributes']['label'], '"');
                             }
                             if (isset($value['attributes']['description'])) {
                                 $strings[$file][] = addcslashes($value['attributes']['description'], '"');
                             }
                         }
                         break;
                 }
             }
             if (is_array($strings[$file])) {
                 $strings[$file] = array_values(array_unique($strings[$file]));
             }
         }
         foreach ($strings as $file => $str) {
             foreach ($str as $msg) {
                 $messages[trim($msg)][] = '#: ' . $file;
             }
         }
         if (is_array($messages)) {
             foreach ($messages as $msgid => $comments) {
                 if (!empty($msgid)) {
                     $catalog->addentry($msgid, null, null, $comments);
                 }
                 #($msgid, $msgid_plural=null, $msgstr=null, $comments=array())
             }
         }
         $catalog->save();
     }
 }