Annotation of /mambo/branches/4.6/administrator/components/com_languages/actions/extract.action.php
Parent Directory
|
Revision Log
Revision 556 - (view) (download)
| 1 : | csouza | 403 | <?php |
| 2 : | class extractAction extends Action | ||
| 3 : | { | ||
| 4 : | |||
| 5 : | function execute(&$controller, &$request) | ||
| 6 : | { | ||
| 7 : | //if (!isset($_POST['domain'])) | ||
| 8 : | |||
| 9 : | csouza | 556 | |
| 10 : | csouza | 403 | $path = mamboCore::get('rootPath'); |
| 11 : | $frontpaths = array("$path/modules", "$path/templates"); | ||
| 12 : | $adminpaths = array("$path/administrator/modules", "$path/administrator/popups", "$path/administrator/templates"); | ||
| 13 : | csouza | 556 | $commonpaths = array("$path/includes", "$path/administrator/includes"); |
| 14 : | csouza | 403 | $cmtpaths = array_merge(glob("$path/administrator/components/com*"), glob("$path/components/com*")); |
| 15 : | |||
| 16 : | csouza | 556 | $language = 'untranslated'; |
| 17 : | set_time_limit(300); | ||
| 18 : | if (!file_exists("$path/language/$language/installation.pot")) { | ||
| 19 : | $this->extract('installation', $path.'/installation', $language); | ||
| 20 : | } | ||
| 21 : | if (!file_exists("$path/language/$language/frontend.pot")) { | ||
| 22 : | $this->extract('frontend', $frontpaths, $language); | ||
| 23 : | } | ||
| 24 : | if (!file_exists("$path/language/$language/administrator.pot")) { | ||
| 25 : | $this->extract('administrator', $adminpaths, $language); | ||
| 26 : | } | ||
| 27 : | |||
| 28 : | if (!file_exists("$path/language/$language/common.pot")) { | ||
| 29 : | $this->extract('common', $commonpaths, $language); | ||
| 30 : | } | ||
| 31 : | |||
| 32 : | csouza | 403 | foreach ($cmtpaths as $path) { |
| 33 : | preg_match('/com_(.*)$/', $path, $matches); | ||
| 34 : | csouza | 556 | $name = $components[$matches[1]][] = $path; |
| 35 : | csouza | 403 | } |
| 36 : | |||
| 37 : | csouza | 556 | foreach ($components as $name => $paths) { |
| 38 : | if (!file_exists("$path/language/$language/$name.pot")) { | ||
| 39 : | $this->extract($name, $paths, $language); | ||
| 40 : | } | ||
| 41 : | } | ||
| 42 : | /**/ | ||
| 43 : | $controller->redirect('index', 'catalogs '); | ||
| 44 : | csouza | 403 | |
| 45 : | } | ||
| 46 : | |||
| 47 : | function extract($domain, $scandirs, $language='untranslated'){ | ||
| 48 : | csouza | 556 | |
| 49 : | csouza | 403 | $path = mamboCore::get('rootPath'); |
| 50 : | csouza | 556 | $textdomain = $path.'/language/'; |
| 51 : | csouza | 403 | $catalog = new PHPGettext_Catalog($domain, $textdomain); |
| 52 : | $catalog->setproperty('mode', _MODE_POT_); | ||
| 53 : | $catalog->setproperty('lang', $language); | ||
| 54 : | csouza | 556 | $headers = $this->header(); |
| 55 : | $catalog->setproperty('comments', $headers[0]); | ||
| 56 : | $catalog->setproperty('headers', $headers[1]); | ||
| 57 : | if (!file_exists("$textdomain/$language/$domain.pot")) { | ||
| 58 : | $catalog->save(); | ||
| 59 : | } | ||
| 60 : | |||
| 61 : | $cwd = getcwd(); | ||
| 62 : | csouza | 403 | chdir($path); |
| 63 : | $this->__extract_xml($domain, $textdomain, $scandirs, $language); | ||
| 64 : | $this->__extract_php($domain, $textdomain, $scandirs, $language); | ||
| 65 : | chdir($cwd); | ||
| 66 : | csouza | 556 | |
| 67 : | csouza | 403 | return true; |
| 68 : | } | ||
| 69 : | |||
| 70 : | function __extract_xml($domain, $path, $scandirs, $language='untranslated') { | ||
| 71 : | $catalog = new PHPGettext_Catalog($domain, $path); | ||
| 72 : | csouza | 556 | $catalog->setproperty('mode', _MODE_POT_); |
| 73 : | csouza | 403 | $catalog->setproperty('lang', $language); |
| 74 : | csouza | 556 | $catalog->load(); |
| 75 : | csouza | 403 | if (is_array($scandirs)) { |
| 76 : | $xml_sources = array(); | ||
| 77 : | foreach ($scandirs as $subdir) { | ||
| 78 : | $xml_sources = array_merge($xml_sources, $this->read_dir($subdir, 'xml')); | ||
| 79 : | } | ||
| 80 : | } else { | ||
| 81 : | $xml_sources = $this->read_dir($scandirs, 'xml'); | ||
| 82 : | } | ||
| 83 : | csouza | 556 | |
| 84 : | csouza | 403 | if (count($xml_sources) > 0) { |
| 85 : | $strings = array(); | ||
| 86 : | foreach ($xml_sources as $file) { | ||
| 87 : | $p = xml_parser_create(); | ||
| 88 : | xml_parser_set_option($p, XML_OPTION_CASE_FOLDING, 0); | ||
| 89 : | csouza | 556 | |
| 90 : | csouza | 403 | xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1); |
| 91 : | xml_parse_into_struct($p, file_get_contents(mamboCore::get('rootPath').'/'.$file), $values); | ||
| 92 : | xml_parser_free($p); | ||
| 93 : | foreach($values as $key => $value) | ||
| 94 : | { | ||
| 95 : | switch ($value['tag']) | ||
| 96 : | { | ||
| 97 : | case 'name': | ||
| 98 : | case 'description': | ||
| 99 : | case 'option': | ||
| 100 : | if (isset($value['value']) && strlen($value['value']) >=1) $strings[$file][] = $value['value']; | ||
| 101 : | break; | ||
| 102 : | case 'param': | ||
| 103 : | if (isset($value['attributes']) && $value['attributes']['type'] != 'spacer') { | ||
| 104 : | if (isset($value['attributes']['label'])) $strings[$file][] = $value['attributes']['label']; | ||
| 105 : | if (isset($value['attributes']['description'])) $strings[$file][] = $value['attributes']['description']; | ||
| 106 : | } | ||
| 107 : | break; | ||
| 108 : | } | ||
| 109 : | } | ||
| 110 : | if (is_array($strings[$file])) | ||
| 111 : | $strings[$file] = array_values(array_unique($strings[$file])); | ||
| 112 : | csouza | 556 | } |
| 113 : | csouza | 403 | foreach ($strings as $file => $str) { |
| 114 : | foreach ($str as $msg) | ||
| 115 : | $messages[trim($msg)][] = '#: '.$file; | ||
| 116 : | } | ||
| 117 : | foreach ($messages as $msgid => $comments) { | ||
| 118 : | if (!empty($msgid)) | ||
| 119 : | $catalog->addentry($msgid, null, null, $comments);#($msgid, $msgid_plural=null, $msgstr=null, $comments=array()) | ||
| 120 : | } | ||
| 121 : | $catalog->save(); | ||
| 122 : | } | ||
| 123 : | } | ||
| 124 : | |||
| 125 : | |||
| 126 : | function __extract_php($domain, $path, $scandirs, $language='untranslated') { | ||
| 127 : | if (is_array($scandirs)) { | ||
| 128 : | $php_sources = array(); | ||
| 129 : | foreach ($scandirs as $subdir) { | ||
| 130 : | $php_sources = array_merge($php_sources, $this->read_dir($subdir, 'php')); | ||
| 131 : | } | ||
| 132 : | } else { | ||
| 133 : | $php_sources = $this->read_dir($scandirs, 'php'); | ||
| 134 : | } | ||
| 135 : | csouza | 556 | |
| 136 : | csouza | 403 | $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"; |
| 137 : | if (file_exists("$path/$language/$domain.pot")) $args = '-j '.$args; | ||
| 138 : | if (count($php_sources) > 20) { | ||
| 139 : | $fp = fopen("$path/$domain.txt", 'w+'); | ||
| 140 : | fwrite($fp, implode("\r\n", $php_sources)); | ||
| 141 : | fclose($fp); | ||
| 142 : | $args = $args." --files-from=$path/$domain.txt"; | ||
| 143 : | } else { | ||
| 144 : | csouza | 556 | $root =str_replace( '\\', '/', mamboCore::get('rootPath') ); |
| 145 : | csouza | 403 | $args = $args." ".implode(" ", $php_sources); |
| 146 : | } | ||
| 147 : | $gettext_admin = new PHPGettextAdmin(); | ||
| 148 : | $gettext_admin->xgettext($args); | ||
| 149 : | @unlink("$path/$domain.txt"); | ||
| 150 : | } | ||
| 151 : | |||
| 152 : | function read_dir($dir, $filetype='php') { | ||
| 153 : | static $root_path; | ||
| 154 : | if (is_null($root_path)) | ||
| 155 : | $root_path = str_replace( '\\', '/', mamboCore::get('rootPath') ); | ||
| 156 : | $array = array(); | ||
| 157 : | $d = dir($dir); | ||
| 158 : | while (false !== ($entry = $d->read())) { | ||
| 159 : | if($entry!='.' && $entry!='..') { | ||
| 160 : | $entry = "$dir/$entry"; | ||
| 161 : | $entry = str_replace( '\\', '/', $entry ); | ||
| 162 : | if(is_dir($entry)) { | ||
| 163 : | $array = array_merge($array, $this->read_dir($entry, $filetype)); | ||
| 164 : | } elseif (preg_match('/.'.$filetype.'$/', $entry)) { | ||
| 165 : | $array[] = str_replace($root_path.'/', '', $entry); | ||
| 166 : | } | ||
| 167 : | } | ||
| 168 : | } | ||
| 169 : | $d->close(); | ||
| 170 : | return $array; | ||
| 171 : | } | ||
| 172 : | |||
| 173 : | function msgcat($lang) { | ||
| 174 : | $root = $_SERVER['DOCUMENT_ROOT'].'/language/'.$lang; | ||
| 175 : | $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 "; | ||
| 176 : | } | ||
| 177 : | function msgcomm($lang) { | ||
| 178 : | $root = $_SERVER['DOCUMENT_ROOT'].'/language/'.$lang; | ||
| 179 : | chdir($root); | ||
| 180 : | $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 "; | ||
| 181 : | } | ||
| 182 : | function msgmerge($lang) { | ||
| 183 : | $root = $_SERVER['DOCUMENT_ROOT'].'/language/'.$lang; | ||
| 184 : | chdir($root); | ||
| 185 : | $cmd = "msgmerge --compendium $lang.po -o frontend.po dummy.po frontend.pot"; | ||
| 186 : | } | ||
| 187 : | |||
| 188 : | |||
| 189 : | function header($charset='utf-8', $plurals='nplurals=2; plural=n == 1 ? 0 : 1;'){ | ||
| 190 : | $year = date('Y'); | ||
| 191 : | $comments = <<<EOT | ||
| 192 : | # Mambo Open Source. | ||
| 193 : | # Copyright (C) 2005 - $year Mambo Foundation Inc. | ||
| 194 : | # This file is distributed under the same license as the Mambo package. | ||
| 195 : | # Translation Team <translation@mambo-foundation.org>, $year# | ||
| 196 : | # | ||
| 197 : | #, fuzzy | ||
| 198 : | EOT; | ||
| 199 : | $comments = explode("\n", $comments); | ||
| 200 : | $headers = array( | ||
| 201 : | 'Project-Id-Version' => 'Mambo 4.6', | ||
| 202 : | 'Report-Msgid-Bugs-To' => 'translation@mambo-foundation.org', | ||
| 203 : | 'POT-Creation-Date' => date('Y-m-d h:iO'), | ||
| 204 : | 'PO-Revision-Date' => date('Y-m-d h:iO'), | ||
| 205 : | 'Last-Translator' => 'Translation <translation@mambo-foundation.org>', | ||
| 206 : | 'Language-Team' => 'Translation <translation@mambo-foundation.org>', | ||
| 207 : | 'MIME-Version' => '1.0', | ||
| 208 : | 'Content-Type' => 'text/plain; charset='.$charset, | ||
| 209 : | 'Content-Transfer-Encoding' => '8bit', | ||
| 210 : | 'Plural-Forms' => $plurals | ||
| 211 : | ); | ||
| 212 : | return array($comments, $headers); | ||
| 213 : | } | ||
| 214 : | } | ||
| 215 : | ?> |
| ViewVC Help | |
| Powered by ViewVC 1.0.0 |
Web Hosting provided by Network Redux.

