[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 #!/usr/bin/env php 2 <?php 3 // 4 // Created on: <31-Mar-2004 11:12:27 amos> 5 // 6 // SOFTWARE NAME: eZ publish 7 // SOFTWARE RELEASE: 3.9.0 8 // BUILD VERSION: 17785 9 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 10 // SOFTWARE LICENSE: GNU General Public License v2.0 11 // NOTICE: > 12 // This program is free software; you can redistribute it and/or 13 // modify it under the terms of version 2.0 of the GNU General 14 // Public License as published by the Free Software Foundation. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of version 2.0 of the GNU General 22 // Public License along with this program; if not, write to the Free 23 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 24 // MA 02110-1301, USA. 25 // 26 // 27 28 include_once ( 'lib/ezutils/classes/ezcli.php' ); 29 include_once ( 'kernel/classes/ezscript.php' ); 30 31 $cli =& eZCLI::instance(); 32 $script =& eZScript::instance( array( 'description' => ( "eZ publish Translation Checker\n\n" . 33 "Will display some statistics on a given translation" . 34 "\n" . 35 "ezchecktranslation.php ita-IT" ), 36 'use-session' => false, 37 'use-modules' => true, 38 'use-extensions' => true ) ); 39 40 $script->startup(); 41 42 $options = $script->getOptions( "[ignore-tr-setup]", 43 "[translation]", 44 array( 'ignore-tr-setup' => 'Tells the analyzer to skip all translations regarding the setup' ) ); 45 $script->initialize(); 46 47 if ( count( $options['arguments'] ) < 1 ) 48 $script->shutdown( 1, "No translation specified" ); 49 50 $translationName = false; 51 $translationFile = $options['arguments'][0]; 52 if ( !file_exists( $translationFile ) ) 53 { 54 $translationName = $translationFile; 55 $translationFile = 'share/translations/' . $translationName . '/translation.ts'; 56 } 57 58 if ( !file_exists( $translationFile ) ) 59 $script->shutdown( 1, "Translation file $translationFile does not exist" ); 60 61 $cli->output( $cli->stylize( 'file', $translationFile ) . ":", false ); 62 $cli->output( " loading", false ); 63 $fd = fopen( $translationFile, "rb" ); 64 $transXML = fread( $fd, filesize( $translationFile ) ); 65 fclose( $fd ); 66 67 include_once ( "lib/ezxml/classes/ezxml.php" ); 68 $xml = new eZXML(); 69 70 $cli->output( " parsing", false ); 71 $tree =& $xml->domTree( $transXML ); 72 73 $cli->output( " validating", false ); 74 include_once ( 'lib/ezi18n/classes/eztstranslator.php' ); 75 if ( !eZTSTranslator::validateDOMTree( $tree ) ) 76 $script->shutdown( 1, "XML text for file $translationFile did not validate" ); 77 78 79 function handleContextNode( $context, &$cli, &$data ) 80 { 81 $contextName = null; 82 $messages = array(); 83 $context_children = $context->children(); 84 foreach( $context_children as $context_child ) 85 { 86 if ( $context_child->type() == 1 ) 87 { 88 if ( $context_child->name() == "name" ) 89 { 90 $data['context_count']++; 91 $name_el = $context_child->children(); 92 if ( count( $name_el ) > 0 ) 93 { 94 $name_el = $name_el[0]; 95 $contextName = $name_el->content(); 96 } 97 } 98 else if ( $context_child->name() == "message" ) 99 { 100 $messages[] = $context_child; 101 } 102 else 103 $cli->warning( "Unknown element name: " . $context_child->name() ); 104 } 105 else 106 $cli->warning( "Unknown DOMnode type: " . $context_child->type() ); 107 } 108 if ( $contextName === null ) 109 { 110 $cli->warning( "No context name found, skipping context" ); 111 return false; 112 } 113 114 if ( !in_array( $contextName, $data['ignored_context_list'] ) ) 115 { 116 foreach( $messages as $message ) 117 { 118 $data['element_count']++; 119 handleMessageNode( $contextName, $message, $cli, $data, true ); 120 } 121 } 122 return true; 123 } 124 125 function handleMessageNode( $contextName, &$message, &$cli, &$data, $requireTranslation ) 126 { 127 $source = null; 128 $translation = null; 129 $comment = null; 130 $message_children =& $message->children(); 131 foreach( $message_children as $message_child ) 132 { 133 if ( $message_child->type() == 1 ) 134 { 135 if ( $message_child->name() == "source" ) 136 { 137 $source_el = $message_child->children(); 138 $source_el = $source_el[0]; 139 $source = $source_el->content(); 140 } 141 else if ( $message_child->name() == "translation" ) 142 { 143 $translation_el = $message_child->children(); 144 $type = $message_child->attributeValue( 'type' ); 145 if ( $type == 'unfinished' ) 146 { 147 $data['untranslated_element_count']++; 148 } 149 else if ( $type == 'obsolete' ) 150 { 151 $data['obsolete_element_count']++; 152 } 153 else 154 { 155 $data['translated_element_count']++; 156 } 157 if ( count( $translation_el ) > 0 ) 158 { 159 $translation_el = $translation_el[0]; 160 $translation = $translation_el->content(); 161 } 162 } 163 else if ( $message_child->name() == "comment" ) 164 { 165 $comment_el = $message_child->children(); 166 $comment_el = $comment_el[0]; 167 $comment = $comment_el->content(); 168 } 169 else 170 $cli->warning( "Unknown element name: " . $message_child->name() ); 171 } 172 else 173 $cli->warning( "Unknown DOMnode type: " . $message_child->type() ); 174 } 175 if ( $source === null ) 176 { 177 $cli->warning( "No source name found, skipping message" ); 178 return false; 179 } 180 if ( $translation === null ) 181 { 182 return false; 183 } 184 return true; 185 } 186 187 $data = array( 'element_count' => 0, 188 'context_count' => 0, 189 'translated_element_count' => 0, 190 'untranslated_element_count' => 0, 191 'obsolete_element_count' => 0 ); 192 $data['ignored_context_list'] = array(); 193 194 if ( $options['ignore-tr-setup'] ) 195 { 196 $data['ignored_context_list'] = array_merge( $data['ignored_context_list'], 197 array( 'design/standard/setup', 198 'design/standard/setup/datatypecode', 199 'design/standard/setup', 200 'design/standard/setup/db', 201 'design/standard/setup/init', 202 'design/standard/setup/operatorcode', 203 'design/standard/setup/tests' ) ); 204 } 205 206 $treeRoot =& $tree->get_root(); 207 $children = $treeRoot->children(); 208 foreach( $children as $child ) 209 { 210 if ( $child->type() == 1 ) 211 { 212 if ( $child->name() == "context" ) 213 { 214 handleContextNode( $child, $cli, $data ); 215 } 216 else 217 $cli->warning( "Unknown element name: " . $child->name() ); 218 } 219 else 220 $cli->warning( "Unknown DOMnode type: " . $child->type() ); 221 } 222 223 $cli->output(); 224 225 $cli->output( $cli->stylize( 'header', "Name" ) . " " . $cli->stylize( "header", "Count" ) ); 226 $cli->output( "context: " . $data['context_count'] ); 227 $cli->output( "element: " . $data['element_count'] ); 228 $cli->output( "translated: " . $data['translated_element_count'] ); 229 $cli->output( "untranslated: " . $data['untranslated_element_count'] ); 230 $cli->output( "obsolete: " . $data['obsolete_element_count'] ); 231 $cli->output(); 232 $totalCount = $data['translated_element_count'] + $data['untranslated_element_count']; 233 if ( $totalCount == 0 ) 234 { 235 $percentText = "no elements"; 236 } 237 else 238 { 239 $percent = ( $data['translated_element_count'] * 100 ) / $totalCount; 240 $percentText = number_format( $percent, 2 ) . "%"; 241 } 242 243 $cli->output( "Percent finished: " . $percentText ); 244 245 $script->shutdown(); 246 247 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |