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

