r32011 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r32010‎ | r32011 | r32012 >
Date:10:37, 15 March 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Use stringmangler for freecol
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageGroups.php
@@ -2379,12 +2379,13 @@
23802380
23812381 protected $description = 'Before starting translating FreeCol to your language, please read [[Translating:FreeCol]] and ask ok from the FreeCol localisation coordinator. Freecol uses GPL-license.';
23822382
2383 - private $fileDir = 'freecol/';
 2383+ private $fileDir = '__BUG__';
23842384
23852385 public function __construct() {
23862386 parent::__construct();
23872387 global $wgTranslateExtensionDirectory;
23882388 $this->fileDir = $wgTranslateExtensionDirectory . 'freecol/';
 2389+ $this->mangler = new StringMatcher( $this->prefix, array( '*' ) );
23892390 }
23902391
23912392 public function getMessage( $key, $code ) {
@@ -2392,26 +2393,38 @@
23932394 return isset( $this->mcache[$code][$key] ) ? $this->mcache[$code][$key] : null;
23942395 }
23952396
2396 - private function load( $code ) {
 2397+ public function getMessageFile( $code ) {
23972398 if ( $code == 'en' ) {
2398 - $filenameXX = $this->fileDir . "FreeColMessages.properties";
 2399+ return 'FreeColMessages.properties';
23992400 } else {
2400 - $filenameXX = $this->fileDir . "freecol_$code";
 2401+ return "freecol_$code";
24012402 }
 2403+ }
24022404
2403 - $linesXX = false;
2404 - if ( file_exists( $filenameXX ) ) {
2405 - $linesXX = file( $filenameXX );
 2405+ protected function getFileLocation( $code ) {
 2406+ return $this->fileDir . $this->getMessageFile( $code );
 2407+ }
 2408+
 2409+ private function load( $code ) {
 2410+ if ( isset($this->mcache[$code]) ) return;
 2411+
 2412+ $filename = $this->getFileLocation( $code );
 2413+
 2414+ $lines = false;
 2415+ if ( file_exists( $filename ) ) {
 2416+ $lines = file( $filename );
24062417 } else {
24072418 # No such localisation, fall out
 2419+ $this->mcache[$code] = null;
24082420 return;
24092421 }
24102422
2411 - if ( !$linesXX) { return; }
2412 - foreach ( $linesXX as $line ) {
 2423+ if ( !$lines ) { return; }
 2424+
 2425+ foreach ( $lines as $line ) {
24132426 if ( !strpos( $line, '=' ) ) { continue; }
24142427 list( $key, $string ) = explode( '=', $line, 2 );
2415 - $this->mcache[$code][$this->prefix . $key] = trim($string);
 2428+ $this->mcache[$code][$this->mangler->mangle($key)] = trim($string);
24162429 }
24172430
24182431 }
@@ -2423,7 +2436,6 @@
24242437
24252438 $array = $this->makeExportArray( $messages );
24262439 foreach ($array as $key => $translation) {
2427 - list(, $key) = explode( '-', $key, 2);
24282440 $txt .= $key . '=' . rtrim( $translation ) . "\n";
24292441 }
24302442 return $txt;

Status & tagging log