r80342 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80341‎ | r80342 | r80343 >
Date:22:46, 14 January 2011
Author:roberthl
Status:deferred
Tags:
Comment:
Add authors write support to Python FFS.
Escape strings on writing to python dictionary.
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/FFS.php
@@ -1086,13 +1086,21 @@
10871087 }
10881088 if( !$ok ) return;
10891089
 1090+ $authors = $this->doAuthors($collection);
 1091+ if( $authors != '' ) fwrite( $this->fw, "\t$authors" );
10901092 fwrite( $this->fw, "\t'{$collection->code}': {\n" );
10911093 fwrite( $this->fw, $this->writeBlock( $collection ) );
10921094 fwrite( $this->fw, "\t},\n" );
10931095 }
10941096
10951097 public function writeIntoVariable( MessageCollection $collection ) {
1096 - return "# -*- coding: utf-8 -*-\nmsg = {\n" . $this->writeBlock( $collection ) . '}';
 1098+ return <<<PHP
 1099+# -*- coding: utf-8 -*-
 1100+{$this->doAuthors($collection)}msg = {
 1101+\t'{$collection->code}': {
 1102+{$this->writeBlock( $collection )}\t}
 1103+}
 1104+PHP;
10971105 }
10981106
10991107 protected function writeBlock( MessageCollection $collection ) {
@@ -1100,11 +1108,24 @@
11011109 $block = '';
11021110 foreach( $collection as $message ) {
11031111 if( $message->translation() == '' ) continue;
1104 - $block .= "\t\t'{$message->key()}': u'{$message->translation()}',\n";
 1112+ $translation = str_replace( '\'', '\\\'', $message->translation() );
 1113+ $block .= "\t\t'{$message->key()}': u'{$translation}',\n";
11051114 }
11061115 return $block;
11071116 }
11081117
 1118+ protected function doAuthors( MessageCollection $collection ) {
 1119+ $output = '';
 1120+ $authors = $collection->getAuthors();
 1121+ $authors = $this->filterAuthors( $authors, $collection->code );
 1122+
 1123+ foreach ( $authors as $author ) {
 1124+ $output .= "# Author: $author\n";
 1125+ }
 1126+
 1127+ return $output;
 1128+ }
 1129+
11091130 public function __destruct() {
11101131 if( $this->fw !== null ) {
11111132 fwrite( $this->fw, "}" );

Status & tagging log