extract('installation', $path.'/installation', $language); if (!file_exists("$path/language/$language/frontend.pot")) $this->extract('frontend', $frontpaths, $language); if (!file_exists("$path/language/$language/administrator.pot")) $this->extract('administrator', $adminpaths, $language); if (!file_exists("$path/language/$language/common.po")) $this->extract('common', $commonpaths, $language); foreach ($cmtpaths as $path) { preg_match('/com_(.*)$/', $path, $matches); $components[$matches[1]][] = $path; } foreach ($components as $name => $paths) $this->extract($name, $paths, $language); #$controller->redirect('index', 'catalogs '); */ } function extract($domain, $scandirs, $language='untranslated'){ set_time_limit(120); $path = mamboCore::get('rootPath'); $textdomain = $path.'/language'; dump($textdomain); $catalog = new PHPGettext_Catalog($domain, $textdomain); $catalog->setproperty('mode', _MODE_POT_); $catalog->setproperty('lang', $language); if (!file_exists("$textdomain/$language/$domain.po")) $catalog->save(); $cwd = getcwd(); chdir($path); $this->__extract_xml($domain, $textdomain, $scandirs, $language); $this->__extract_php($domain, $textdomain, $scandirs, $language); chdir($cwd); $catalog->load(); $headers = $this->header(); $catalog->setproperty('comments', $headers[0]); $catalog->setproperty('headers', $headers[1]); $catalog->save(); chdir($cwd); return true; } function __extract_xml($domain, $path, $scandirs, $language='untranslated') { $catalog = new PHPGettext_Catalog($domain, $path); $catalog->setproperty('mode', _MODE_PO_); $catalog->setproperty('lang', $language); if (is_array($scandirs)) { $xml_sources = array(); foreach ($scandirs as $subdir) { $xml_sources = array_merge($xml_sources, $this->read_dir($subdir, 'xml')); } } else { $xml_sources = $this->read_dir($scandirs, 'xml'); } 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': if (isset($value['value']) && strlen($value['value']) >=1) $strings[$file][] = $value['value']; break; case 'param': if (isset($value['attributes']) && $value['attributes']['type'] != 'spacer') { if (isset($value['attributes']['label'])) $strings[$file][] = $value['attributes']['label']; if (isset($value['attributes']['description'])) $strings[$file][] = $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; } foreach ($messages as $msgid => $comments) { if (!empty($msgid)) $catalog->addentry($msgid, null, null, $comments);#($msgid, $msgid_plural=null, $msgstr=null, $comments=array()) } $catalog->save(); } } function __extract_php($domain, $path, $scandirs, $language='untranslated') { if (is_array($scandirs)) { $php_sources = array(); foreach ($scandirs as $subdir) { $php_sources = array_merge($php_sources, $this->read_dir($subdir, 'php')); } } else { $php_sources = $this->read_dir($scandirs, 'php'); } $args = "-n -c --sort-by-file --keyword=T_ --keyword=Tn_:1,2 --keyword=Td_:2 --keyword=Tdn_:2,3 --output-dir=$path/$language -o $domain.pot"; if (file_exists("$path/$language/$domain.pot")) $args = '-j '.$args; if (count($php_sources) > 20) { $fp = fopen("$path/$domain.txt", 'w+'); fwrite($fp, implode("\r\n", $php_sources)); fclose($fp); $args = $args." --files-from=$path/$domain.txt"; } else { $root =str_replace( '\\', '/', mamboCore::get('rootPath') ); $args = $args." ".implode(" ", $php_sources); } $gettext_admin = new PHPGettextAdmin(); $gettext_admin->xgettext($args); @unlink("$path/$domain.txt"); } function read_dir($dir, $filetype='php') { static $root_path; if (is_null($root_path)) $root_path = str_replace( '\\', '/', mamboCore::get('rootPath') ); $array = array(); $d = dir($dir); while (false !== ($entry = $d->read())) { if($entry!='.' && $entry!='..') { $entry = "$dir/$entry"; $entry = str_replace( '\\', '/', $entry ); if(is_dir($entry)) { $array = array_merge($array, $this->read_dir($entry, $filetype)); } elseif (preg_match('/.'.$filetype.'$/', $entry)) { $array[] = str_replace($root_path.'/', '', $entry); } } } $d->close(); return $array; } function msgcat($lang) { $root = $_SERVER['DOCUMENT_ROOT'].'/language/'.$lang; $cmd = "msgcat --use-first -o compendium.po com_contacts.po com_banners.po com_wrapper.po com_newsfeeds.po com_contacts.po com_messages.po com_login.po frontend_.po "; } function msgcomm($lang) { $root = $_SERVER['DOCUMENT_ROOT'].'/language/'.$lang; chdir($root); $cmd = "msgcomm -o compendium.po com_contacts.po com_banners.po com_wrapper.po com_newsfeeds.po com_contacts.po com_messages.po frontend_.po "; } function msgmerge($lang) { $root = $_SERVER['DOCUMENT_ROOT'].'/language/'.$lang; chdir($root); $cmd = "msgmerge --compendium $lang.po -o frontend.po dummy.po frontend.pot"; } function header($charset='utf-8', $plurals='nplurals=2; plural=n == 1 ? 0 : 1;'){ $year = date('Y'); $comments = <<, $year# # #, fuzzy EOT; $comments = explode("\n", $comments); $headers = array( 'Project-Id-Version' => 'Mambo 4.6', 'Report-Msgid-Bugs-To' => 'translation@mambo-foundation.org', 'POT-Creation-Date' => date('Y-m-d h:iO'), 'PO-Revision-Date' => date('Y-m-d h:iO'), 'Last-Translator' => 'Translation ', 'Language-Team' => 'Translation ', 'MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset='.$charset, 'Content-Transfer-Encoding' => '8bit', 'Plural-Forms' => $plurals ); return array($comments, $headers); } } ?>