Index: trunk/extensions/Translate/MessageCollection.php |
— | — | @@ -30,6 +30,8 @@ |
31 | 31 | |
32 | 32 | // Tags, copied to thin messages |
33 | 33 | private $tags = array(); // tagtype => keys |
| 34 | + |
| 35 | + protected $authors = array(); |
34 | 36 | |
35 | 37 | // Constructors etc. |
36 | 38 | // |
— | — | @@ -68,7 +70,7 @@ |
69 | 71 | |
70 | 72 | $this->loadTranslations(); |
71 | 73 | |
72 | | - $authors = (array) $this->authors; |
| 74 | + $authors = array_flip( $this->authors ); |
73 | 75 | foreach ( $this->messages as $m ) { |
74 | 76 | // Check if there is authors |
75 | 77 | $author = $m->author(); |
— | — | @@ -80,7 +82,8 @@ |
81 | 83 | } |
82 | 84 | } |
83 | 85 | |
84 | | - arsort( $authors, SORT_NUMERIC ); |
| 86 | + #arsort( $authors, SORT_NUMERIC ); |
| 87 | + ksort( $authors ); |
85 | 88 | foreach ( $authors as $author => $edits ) { |
86 | 89 | if ( $author !== $wgTranslateFuzzyBotName ) { |
87 | 90 | $filteredAuthors[] = $author; |
— | — | @@ -107,6 +110,7 @@ |
108 | 111 | |
109 | 112 | public function loadTranslations() { |
110 | 113 | $this->loadData( $this->keys ); |
| 114 | + $this->loadInfo( $this->keys ); |
111 | 115 | $this->initMessages(); |
112 | 116 | } |
113 | 117 | |
— | — | @@ -333,7 +337,6 @@ |
334 | 338 | |
335 | 339 | public function initMessages() { |
336 | 340 | if ( $this->messages !== null ) return; |
337 | | - |
338 | 341 | $messages = array(); |
339 | 342 | |
340 | 343 | foreach ( array_keys($this->keys) as $key ) { |
Index: trunk/extensions/Translate/scripts/export.php |
— | — | @@ -56,6 +56,15 @@ |
57 | 57 | STDERR( "Invalid group" ); |
58 | 58 | exit( 1 ); |
59 | 59 | } |
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 @@ |
84 | 84 | if ( !file_exists($writePath) ) throw new MWException( "Write path '$writePath' does not exists" ); |
85 | 85 | if ( !is_writable($writePath) ) throw new MWException( "Write path '$writePath' is not writable" ); |
86 | 86 | |
87 | | - $targetFile = $writePath . '/' . $this->group->getTargetFilename( $code ); |
| 87 | + $targetFile = $writePath . '/' . $this->group->getTargetFilename( $collection->code ); |
88 | 88 | |
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 ); |
92 | 91 | } else { |
93 | | - $sourceFile = $targetFile; |
| 92 | + $sourceFile = $this->group->getSourceFilePath( $collection->code ); |
| 93 | + $this->tryReadSource( $sourceFile, $collection ); |
94 | 94 | } |
95 | 95 | |
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 | + } |
103 | 99 | |
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 ); |
106 | 104 | } |
107 | 105 | |
108 | | - public function writeIntoVariable( MessageCollection $collection ) { |
| 106 | + protected function writeReal( MessageCollection $collection ) { |
109 | 107 | $output = ''; |
110 | 108 | |
111 | 109 | $authors = $collection->getAuthors(); |
— | — | @@ -122,6 +120,16 @@ |
123 | 121 | return $output; |
124 | 122 | } |
125 | 123 | |
| 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 | + |
126 | 134 | protected function tryReadFile( $filename ) { |
127 | 135 | if ( !$filename ) return false; |
128 | 136 | if ( !file_exists($filename) ) return false; |
— | — | @@ -206,9 +214,11 @@ |
207 | 215 | // WRITE |
208 | 216 | // |
209 | 217 | |
210 | | - public function writeIntoVariable( MessageCollection $collection ) { |
| 218 | + protected function writeReal( MessageCollection $collection ) { |
| 219 | + |
211 | 220 | $output = $this->doHeader( $collection ); |
212 | 221 | $output .= $this->doAuthors( $collection ); |
| 222 | + $output .= "\n"; |
213 | 223 | |
214 | 224 | $mangler = $this->group->getMangler(); |
215 | 225 | foreach ( $collection as $key => $m ) { |
— | — | @@ -228,12 +238,15 @@ |
229 | 239 | } |
230 | 240 | |
231 | 241 | 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"; |
236 | 242 | 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"; |
238 | 251 | } |
239 | 252 | return $output; |
240 | 253 | } |
— | — | @@ -243,7 +256,7 @@ |
244 | 257 | $authors = $collection->getAuthors(); |
245 | 258 | $authors = $this->filterAuthors( $authors, $collection->code ); |
246 | 259 | foreach ( $authors as $author ) { |
247 | | - $output .= "# $author\n"; |
| 260 | + $output .= "# Author: $author\n"; |
248 | 261 | } |
249 | 262 | return $output; |
250 | 263 | } |
Index: trunk/extensions/Translate/groups/FreeCol/FreeCol.yml |
— | — | @@ -47,4 +47,4 @@ |
48 | 48 | - shipName.3.0 |
49 | 49 | - model.region.default |
50 | 50 | 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 @@ |
247 | 247 | |
248 | 248 | |
249 | 249 | 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 | + } |
252 | 257 | |
253 | 258 | return Xml::openElement( 'textarea', array( 'id' => 'wpTextbox1', 'rows' => '50' ) ) . |
254 | 259 | $data . |
— | — | @@ -263,9 +268,15 @@ |
264 | 269 | } |
265 | 270 | |
266 | 271 | public function output() { |
267 | | - $writer = $this->group->getWriter(); |
268 | 272 | $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; |
270 | 281 | } |
271 | 282 | } |
272 | 283 | |
Index: trunk/extensions/Translate/Groups.php |
— | — | @@ -170,6 +170,19 @@ |
171 | 171 | return (bool) count($data['MESSAGES']); |
172 | 172 | } |
173 | 173 | |
| 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 | + |
174 | 187 | public function getSourceFilePath( $code ) { |
175 | 188 | if ( $code === 'en' ) { |
176 | 189 | $pattern = $this->getFromConf( 'FILES', 'definitionFile' ); |