r53642 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53641‎ | r53642 | r53643 >
Date:10:48, 22 July 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
* Typoe in FreeCol.yml
* Bugfixes in message collection, ffs
* FC fixes in TranslateTasks and export
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)
  • /trunk/extensions/Translate/Groups.php (modified) (history)
  • /trunk/extensions/Translate/MessageCollection.php (modified) (history)
  • /trunk/extensions/Translate/TranslateTasks.php (modified) (history)
  • /trunk/extensions/Translate/groups/FreeCol/FreeCol.yml (modified) (history)
  • /trunk/extensions/Translate/scripts/export.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageCollection.php
@@ -30,6 +30,8 @@
3131
3232 // Tags, copied to thin messages
3333 private $tags = array(); // tagtype => keys
 34+
 35+ protected $authors = array();
3436
3537 // Constructors etc.
3638 //
@@ -68,7 +70,7 @@
6971
7072 $this->loadTranslations();
7173
72 - $authors = (array) $this->authors;
 74+ $authors = array_flip( $this->authors );
7375 foreach ( $this->messages as $m ) {
7476 // Check if there is authors
7577 $author = $m->author();
@@ -80,7 +82,8 @@
8183 }
8284 }
8385
84 - arsort( $authors, SORT_NUMERIC );
 86+ #arsort( $authors, SORT_NUMERIC );
 87+ ksort( $authors );
8588 foreach ( $authors as $author => $edits ) {
8689 if ( $author !== $wgTranslateFuzzyBotName ) {
8790 $filteredAuthors[] = $author;
@@ -107,6 +110,7 @@
108111
109112 public function loadTranslations() {
110113 $this->loadData( $this->keys );
 114+ $this->loadInfo( $this->keys );
111115 $this->initMessages();
112116 }
113117
@@ -333,7 +337,6 @@
334338
335339 public function initMessages() {
336340 if ( $this->messages !== null ) return;
337 -
338341 $messages = array();
339342
340343 foreach ( array_keys($this->keys) as $key ) {
Index: trunk/extensions/Translate/scripts/export.php
@@ -56,6 +56,15 @@
5757 STDERR( "Invalid group" );
5858 exit( 1 );
5959 }
60 -
61 -$writer = $group->getWriter();
62 -$writer->fileExport( $langs, $options['target'] );
 60+if ( $group instanceof FileBasedMessageGroup ) {
 61+ $ffs = $group->getFFS();
 62+ $ffs->setWritePath( $options['target'] );
 63+ $collection = $group->initCollection( 'en' );
 64+ foreach ( $langs as $lang ) {
 65+ $collection->resetForNewLanguage( $lang );
 66+ $ffs->write( $collection );
 67+ }
 68+} else {
 69+ $writer = $group->getWriter();
 70+ $writer->fileExport( $langs, $options['target'] );
 71+}
Index: trunk/extensions/Translate/FFS.php
@@ -83,28 +83,26 @@
8484 if ( !file_exists($writePath) ) throw new MWException( "Write path '$writePath' does not exists" );
8585 if ( !is_writable($writePath) ) throw new MWException( "Write path '$writePath' is not writable" );
8686
87 - $targetFile = $writePath . '/' . $this->group->getTargetFilename( $code );
 87+ $targetFile = $writePath . '/' . $this->group->getTargetFilename( $collection->code );
8888
89 - if ( !file_exists($targetFile) ) {
90 - // May be null
91 - $sourceFile = $this->group->geSourceFilePath( $code );
 89+ if ( file_exists($targetFile) ) {
 90+ $this->tryReadSource( $targetFile, $collection );
9291 } else {
93 - $sourceFile = $targetFile;
 92+ $sourceFile = $this->group->getSourceFilePath( $collection->code );
 93+ $this->tryReadSource( $sourceFile, $collection );
9494 }
9595
96 - $sourceText = $this->tryReadFile( $sourceFile );
97 - if ( $sourceText !== false ) {
98 - $sourceData = $this->readFromVariable( $sourceText );
99 - if ( isset( $sourceData['AUTHORS'] ) ) {
100 - $collection->addCollectionAuthors( $sourceData['AUTHORS'] );
101 - }
102 - }
 96+ $output = $this->writeReal( $collection );
 97+ file_put_contents( $targetFile, $output );
 98+ }
10399
104 - $output = $this->writeIntoVariable( $collection );
105 - file_put_contents( $filename, $output );
 100+ public function writeIntoVariable( MessageCollection $collection ) {
 101+ $sourceFile = $this->group->getSourceFilePath( $collection->code );
 102+ $this->tryReadSource( $sourceFile, $collection );
 103+ return $this->writeReal( $collection );
106104 }
107105
108 - public function writeIntoVariable( MessageCollection $collection ) {
 106+ protected function writeReal( MessageCollection $collection ) {
109107 $output = '';
110108
111109 $authors = $collection->getAuthors();
@@ -122,6 +120,16 @@
123121 return $output;
124122 }
125123
 124+ protected function tryReadSource( $filename, $collection ) {
 125+ $sourceText = $this->tryReadFile( $filename );
 126+ if ( $sourceText !== false ) {
 127+ $sourceData = $this->readFromVariable( $sourceText );
 128+ if ( isset( $sourceData['AUTHORS'] ) ) {
 129+ $collection->addCollectionAuthors( $sourceData['AUTHORS'] );
 130+ }
 131+ }
 132+ }
 133+
126134 protected function tryReadFile( $filename ) {
127135 if ( !$filename ) return false;
128136 if ( !file_exists($filename) ) return false;
@@ -206,9 +214,11 @@
207215 // WRITE
208216 //
209217
210 - public function writeIntoVariable( MessageCollection $collection ) {
 218+ protected function writeReal( MessageCollection $collection ) {
 219+
211220 $output = $this->doHeader( $collection );
212221 $output .= $this->doAuthors( $collection );
 222+ $output .= "\n";
213223
214224 $mangler = $this->group->getMangler();
215225 foreach ( $collection as $key => $m ) {
@@ -228,12 +238,15 @@
229239 }
230240
231241 protected function doHeader( MessageCollection $collection ) {
232 - $code = $collection->code;
233 - $name = TranslateUtils::getLanguageName( $code );
234 - $native = TranslateUtils::getLanguageName( $code, true );
235 - $output = "# Messages for $name ($native)\n";
236242 if ( isset($this->extra['header']) ) {
237 - $output .= $this->extra['header'];
 243+ $output = $this->extra['header'];
 244+ } else {
 245+ global $wgSitename;
 246+ $code = $collection->code;
 247+ $name = TranslateUtils::getLanguageName( $code );
 248+ $native = TranslateUtils::getLanguageName( $code, true );
 249+ $output = "# Messages for $name ($native)\n";
 250+ $output .= "# Exported from $wgSitename\n";
238251 }
239252 return $output;
240253 }
@@ -243,7 +256,7 @@
244257 $authors = $collection->getAuthors();
245258 $authors = $this->filterAuthors( $authors, $collection->code );
246259 foreach ( $authors as $author ) {
247 - $output .= "# $author\n";
 260+ $output .= "# Author: $author\n";
248261 }
249262 return $output;
250263 }
Index: trunk/extensions/Translate/groups/FreeCol/FreeCol.yml
@@ -47,4 +47,4 @@
4848 - shipName.3.0
4949 - model.region.default
5050 ignored:
51 - - headerFont
\ No newline at end of file
 51+ - HeaderFont
\ No newline at end of file
Index: trunk/extensions/Translate/TranslateTasks.php
@@ -246,8 +246,13 @@
247247
248248
249249 public function output() {
250 - $writer = $this->group->getWriter();
251 - $data = $writer->webExport( $this->collection );
 250+ if ( $this->group instanceof FileBasedMessageGroup ) {
 251+ $ffs = $this->group->getFFS();
 252+ $data = $ffs->writeIntoVariable( $this->collection );
 253+ } else {
 254+ $writer = $this->group->getWriter();
 255+ $data = $writer->webExport( $this->collection );
 256+ }
252257
253258 return Xml::openElement( 'textarea', array( 'id' => 'wpTextbox1', 'rows' => '50' ) ) .
254259 $data .
@@ -263,9 +268,15 @@
264269 }
265270
266271 public function output() {
267 - $writer = $this->group->getWriter();
268272 $this->collection->filter( 'translated', false );
269 - return $writer->webExport( $this->collection );
 273+ if ( $this->group instanceof FileBasedMessageGroup ) {
 274+ $ffs = $this->group->getFFS();
 275+ $data = $ffs->writeIntoVariable( $this->collection );
 276+ } else {
 277+ $writer = $this->group->getWriter();
 278+ $data = $writer->webExport( $this->collection );
 279+ }
 280+ return $data;
270281 }
271282 }
272283
Index: trunk/extensions/Translate/Groups.php
@@ -170,6 +170,19 @@
171171 return (bool) count($data['MESSAGES']);
172172 }
173173
 174+ public function load( $code ) {
 175+ $cache = new MessageGroupCache( $this->getId() );
 176+ if ( $cache->exists() ) {
 177+ return parent::load( $code );
 178+ } else {
 179+ // Short-circuit cache
 180+ $ffs = $this->getFFS();
 181+ if ( !$ffs ) throw new MWException( 'No FFS defined' );
 182+ $data = $ffs->read( $code );
 183+ return $data['MESSAGES'];
 184+ }
 185+ }
 186+
174187 public function getSourceFilePath( $code ) {
175188 if ( $code === 'en' ) {
176189 $pattern = $this->getFromConf( 'FILES', 'definitionFile' );

Status & tagging log