r22820 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22819‎ | r22820 | r22821 >
Date:19:02, 7 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Fix up the oncoming i18n trainwreck here;

* Move translations to a .i18n.php file as with other extensions
* Use English as a fallback (as before), but if a translation is available for some (or all) magic words, use that, i.e. fall back to English when a translation isn't available for a given word, to avoid breakage when a new one is introduced
Modified paths:
  • /trunk/extensions/ParserFunctions/ParserFunctions.i18n.php.php (added) (history)
  • /trunk/extensions/ParserFunctions/ParserFunctions.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ParserFunctions/ParserFunctions.i18n.php.php
@@ -0,0 +1,66 @@
 2+<?php
 3+
 4+/**
 5+ * Get translated magic words, if available
 6+ *
 7+ * @param string $lang Language code
 8+ * @return array
 9+ */
 10+function efParserFunctionsWords( $lang ) {
 11+ $words = array();
 12+
 13+ /**
 14+ * English
 15+ */
 16+ $words['en'] = array(
 17+ 'expr' => array( 0, 'expr' ),
 18+ 'if' => array( 0, 'if' ),
 19+ 'ifeq' => array( 0, 'ifeq' ),
 20+ 'ifexpr' => array( 0, 'ifexpr' ),
 21+ 'switch' => array( 0, 'switch' ),
 22+ 'default' => array( 0, '#default' ),
 23+ 'ifexist' => array( 0, 'ifexist' ),
 24+ 'time' => array( 0, 'time' ),
 25+ 'rel2abs' => array( 0, 'rel2abs' ),
 26+ 'titleparts' => array( 0, 'titleparts' ),
 27+ );
 28+
 29+ /**
 30+ * Farsi-Persian
 31+ */
 32+ $words['fa'] = array(
 33+ 'expr' => array( 0, 'حساب', 'expr' ),
 34+ 'if' => array( 0, 'اگر', 'if' ),
 35+ 'ifeq' => array( 0, 'اگرمساوی', 'ifeq' ),
 36+ 'ifexpr' => array( 0, 'اگرحساب', 'ifexpr' ),
 37+ 'switch' => array( 0, 'گزینه', 'switch' ),
 38+ 'default' => array( 0, '#پیش‌فرض', '#default' ),
 39+ 'ifexist' => array( 0, 'اگرموجود', 'ifexist' ),
 40+ 'time' => array( 0, 'زمان', 'time' ),
 41+ 'rel2abs' => array( 0, 'نسبی‌به‌مطلق', 'rel2abs' ),
 42+ );
 43+
 44+ /**
 45+ * Hebrew
 46+ */
 47+ $words['he'] => array(
 48+ 'expr' => array( 0, 'חשב', 'expr' ),
 49+ 'if' => array( 0, 'תנאי', 'if' ),
 50+ 'ifeq' => array( 0, 'שווה', 'ifeq' ),
 51+ 'ifexpr' => array( 0, 'חשב תנאי', 'ifexpr' ),
 52+ 'switch' => array( 0, 'בחר', 'switch' ),
 53+ 'default' => array( 0, '#ברירת מחדל', '#default' ),
 54+ 'ifexist' => array( 0, 'קיים', 'ifexist' ),
 55+ 'time' => array( 0, 'זמן', 'time' ),
 56+ 'rel2abs' => array( 0, 'יחסי למוחלט', 'rel2abs' ),
 57+ 'titleparts' => array( 0, 'חלק בכותרת', 'titleparts' ),
 58+ );
 59+
 60+ # English is used as a fallback, and the English synonyms are
 61+ # used if a translation has not been provided for a given word
 62+ return ( $lang == 'en' || !isset( $words[$lang] ) )
 63+ ? $words['en']
 64+ : array_merge( $words['en'], $words[$lang] );
 65+}
 66+
 67+?>
\ No newline at end of file
Property changes on: trunk/extensions/ParserFunctions/ParserFunctions.i18n.php.php
___________________________________________________________________
Added: svn:eol-style
168 + native
Index: trunk/extensions/ParserFunctions/ParserFunctions.php
@@ -269,43 +269,9 @@
270270 }
271271
272272 function wfParserFunctionsLanguageGetMagic( &$magicWords, $langCode ) {
273 - switch ( $langCode ) {
274 - case 'fa':
275 - $magicWords['expr'] = array( 0, 'حساب', 'expr' );
276 - $magicWords['if'] = array( 0, 'اگر', 'if' );
277 - $magicWords['ifeq'] = array( 0, 'اگرمساوی', 'ifeq' );
278 - $magicWords['ifexpr'] = array( 0, 'اگرحساب', 'ifexpr' );
279 - $magicWords['switch'] = array( 0, 'گزینه', 'switch' );
280 - $magicWords['default'] = array( 0, '#پیش‌فرض', '#default' );
281 - $magicWords['ifexist'] = array( 0, 'اگرموجود', 'ifexist' );
282 - $magicWords['time'] = array( 0, 'زمان', 'time' );
283 - $magicWords['rel2abs'] = array( 0, 'نسبی‌به‌مطلق', 'rel2abs' );
284 - $magicWords['titleparts'] = array( 0, 'titleparts' ); # TODO: translate
285 - break;
286 - case 'he':
287 - $magicWords['expr'] = array( 0, 'חשב', 'expr' );
288 - $magicWords['if'] = array( 0, 'תנאי', 'if' );
289 - $magicWords['ifeq'] = array( 0, 'שווה', 'ifeq' );
290 - $magicWords['ifexpr'] = array( 0, 'חשב תנאי', 'ifexpr' );
291 - $magicWords['switch'] = array( 0, 'בחר', 'switch' );
292 - $magicWords['default'] = array( 0, '#ברירת מחדל', '#default' );
293 - $magicWords['ifexist'] = array( 0, 'קיים', 'ifexist' );
294 - $magicWords['time'] = array( 0, 'זמן', 'time' );
295 - $magicWords['rel2abs'] = array( 0, 'יחסי למוחלט', 'rel2abs' );
296 - $magicWords['titleparts'] = array( 0, 'חלק בכותרת', 'titleparts' );
297 - break;
298 - default:
299 - $magicWords['expr'] = array( 0, 'expr' );
300 - $magicWords['if'] = array( 0, 'if' );
301 - $magicWords['ifeq'] = array( 0, 'ifeq' );
302 - $magicWords['ifexpr'] = array( 0, 'ifexpr' );
303 - $magicWords['switch'] = array( 0, 'switch' );
304 - $magicWords['default'] = array( 0, '#default' );
305 - $magicWords['ifexist'] = array( 0, 'ifexist' );
306 - $magicWords['time'] = array( 0, 'time' );
307 - $magicWords['rel2abs'] = array( 0, 'rel2abs' );
308 - $magicWords['titleparts'] = array( 0, 'titleparts' );
309 - }
 273+ require_once( dirname( __FILE__ ) . '/ParserFunctions.i18n.php' );
 274+ foreach( efParserFunctionsWords( $langCode ) as $word => $trans )
 275+ $magicWords[$word] = $trans;
310276 return true;
311277 }
312278

Status & tagging log