r55138 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55137‎ | r55138 | r55139 >
Date:12:13, 16 August 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
Updates for FUDforum support
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/groups/FUDforum/Checker.php (added) (history)
  • /trunk/extensions/Translate/groups/FUDforum/FUDforum.yml (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/FFS.php
@@ -95,7 +95,10 @@
9696 }
9797
9898 $output = $this->writeReal( $collection );
99 - file_put_contents( $targetFile, $output );
 99+ if ( $output ) {
 100+ wfMkdirParents( dirname( $targetFile ), null, __METHOD__ );
 101+ file_put_contents( $targetFile, $output );
 102+ }
100103 }
101104
102105 public function writeIntoVariable( MessageCollection $collection ) {
@@ -224,11 +227,11 @@
225228 //
226229
227230 protected function writeReal( MessageCollection $collection ) {
228 -
229 - $output = $this->doHeader( $collection );
230 - $output .= $this->doAuthors( $collection );
231 - $output .= "\n";
232 -
 231+ $header = $this->doHeader( $collection );
 232+ $header .= $this->doAuthors( $collection );
 233+ $header .= "\n";
 234+
 235+ $output = '';
233236 $mangler = $this->group->getMangler();
234237 foreach ( $collection as $key => $m ) {
235238 $key = $mangler->unmangle( $key );
@@ -243,7 +246,10 @@
244247 if ( $m->hasTag( 'fuzzy' ) ) $output .= "# Fuzzy\n";
245248 $output .= "$key{$this->keySeparator}$value\n";
246249 }
247 - return $output;
 250+
 251+ if ( $output ) {
 252+ return $header.$output;
 253+ }
248254 }
249255
250256 protected function doHeader( MessageCollection $collection ) {
Index: trunk/extensions/Translate/MessageGroups.php
@@ -725,10 +725,17 @@
726726
727727 wfRunHooks( 'TranslatePostInitGroups', array( &$wgTranslateCC ) );
728728
729 - global $wgTranslateGroupFiles;
 729+ global $wgTranslateGroupFiles, $wgAutoloadClasses;
730730 foreach ( $wgTranslateGroupFiles as $file ) {
731731 wfDebug( $file."\n" );
732732 $conf = TranslateSpyc::load($file);
 733+ if ( !empty($conf['AUTOLOAD']) && is_array($conf['AUTOLOAD']) ) {
 734+ $dir = dirname($file);
 735+ foreach( $conf['AUTOLOAD'] as $class => $file ) {
 736+ $wgAutoloadClasses[$class] = "$dir/$file";
 737+ }
 738+ }
 739+
733740 $group = MessageGroupBase::factory( $conf );
734741 $wgTranslateCC[$group->getId()] = $group;
735742 }
Index: trunk/extensions/Translate/groups/FUDforum/FUDforum.yml
@@ -11,7 +11,7 @@
1212 class: JavaFFS
1313 keySeparator: ":"
1414 sourcePattern: %GROUPROOT%/fudforum/install/forum_data/thm/default/i18n/%CODE%/msg
15 - targetPattern: %CODE%/msg
 15+ targetPattern: i18n/%CODE%/msg
1616 codeMap:
1717 af: afrikaans
1818 ar: arabic
@@ -43,7 +43,7 @@
4444 lv: latvian
4545 nl: dutch
4646 nn: norwegian_nynorsk
47 - no: norwegian_bokmal
 47+ no: norwegian # BC
4848 oc: occitan
4949 pl: polish
5050 pt-br: portuguese_br
@@ -60,5 +60,15 @@
6161 ur: urdu
6262 vi: vietnamese
6363 vo: volapuk
64 - zh-hans: chinese_simplified
65 - zh-hant: chinese_traditional
\ No newline at end of file
 64+ zh-hans: chinese # BC
 65+ zh-hant: chinese_traditional
 66+
 67+
 68+CHECKER:
 69+ class: FUDforumMessageChecker
 70+ checks:
 71+ - FUDforumVariablesCheck
 72+ - braceBalanceCheck
 73+
 74+AUTOLOAD:
 75+ FUDforumMessageChecker: Checker.php
\ No newline at end of file
Index: trunk/extensions/Translate/groups/FUDforum/Checker.php
@@ -0,0 +1,52 @@
 2+<?php
 3+ /**
 4+ * @file
 5+ * @copyright Copyright © 2009, Niklas Laxström
 6+ * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
 7+ */
 8+class FUDforumMessageChecker extends MessageChecker {
 9+
 10+ /**
 11+ * Checks for missing and unknown variables in translations.
 12+ *
 13+ * @param $messages Iterable list of TMessages.
 14+ * @param $code Language code of the translations.
 15+ * @param $warnings Array where warnings are appended to.
 16+ */
 17+ protected function FUDforumVariablesCheck( $messages, $code, &$warnings ) {
 18+ foreach( $messages as $message ) {
 19+ $key = $message->key();
 20+ $definition = $message->definition();
 21+ $translation = $message->translation();
 22+
 23+ $varPattern = '{.*}';
 24+ preg_match_all( "/$varPattern/U", $definition, $defVars );
 25+ preg_match_all( "/$varPattern/U", $translation, $transVars );
 26+
 27+ # Check for missing variables in the translation
 28+ $subcheck = 'missing';
 29+ $params = self::compareArrays( $defVars[0], $transVars[0] );
 30+ if ( count($params) ) {
 31+ $warnings[$key][] = array(
 32+ array( 'variable', $subcheck, $key, $code ),
 33+ 'translate-checks-parameters',
 34+ array( 'PARAMS', $params ),
 35+ array( 'COUNT', count($params) ),
 36+ );
 37+ }
 38+
 39+ # Check for unknown variables in the translation
 40+ $subcheck = 'unknown';
 41+ $params = self::compareArrays( $transVars[0], $defVars[0] );
 42+ if ( count($params) ) {
 43+ $warnings[$key][] = array(
 44+ array( 'variable', $subcheck, $key, $code ),
 45+ 'translate-checks-parameters-unknown',
 46+ array( 'PARAMS', $params ),
 47+ array( 'COUNT', count($params) ),
 48+ );
 49+ }
 50+ }
 51+ }
 52+
 53+}
\ No newline at end of file
Property changes on: trunk/extensions/Translate/groups/FUDforum/Checker.php
___________________________________________________________________
Name: svn:eol-style
154 + native

Status & tagging log