Index: trunk/extensions/NaturalLanguageList/NaturalLanguageList.i18n.magic.php |
— | — | @@ -0,0 +1,12 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$magicWords = array(); |
| 5 | + |
| 6 | +$magicWords['en'] = array( |
| 7 | + 'nll_blanks' => array( 0, 'blanks' ), |
| 8 | + 'nll_duplicates' => array( 0, 'duplicates' ), |
| 9 | + 'nll_itemcover' => array( 0, 'itemcover' ), |
| 10 | + 'nll_fieldsperitem' => array( 0, 'itemsperitem', 'fieldsperitem' ), |
| 11 | + 'nll_lastseparator' => array( 0, 'lastseparator' ), |
| 12 | + 'nll_outputseparator' => array( 0, 'outputseparator', 'separator' ), |
| 13 | +); |
Property changes on: trunk/extensions/NaturalLanguageList/NaturalLanguageList.i18n.magic.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 14 | + native |
Index: trunk/extensions/NaturalLanguageList/NaturalLanguageList.i18n.php |
— | — | @@ -1,4 +1,6 @@ |
2 | 2 | <?php |
| 3 | + |
| 4 | +require_once( dirname(__FILE__) . '/NaturalLanguageList.i18n.magic.php' ); |
3 | 5 | $messages['en'] = array ( |
4 | 6 | 'nll-itemcover' => '$1', |
5 | 7 | 'nll-separator' => ', ', |
Index: trunk/extensions/NaturalLanguageList/NaturalLanguageList.php |
— | — | @@ -320,26 +320,18 @@ |
321 | 321 | } |
322 | 322 | } |
323 | 323 | # Still here? Then it must be an option |
324 | | - switch ( trim( $var ) ) { |
| 324 | + switch ( $name = self::parseOptionName( $var ) ) { |
325 | 325 | case 'duplicates': |
326 | | - $this->mOptions['duplicates'] = self::trueCheck ( $value ); |
327 | | - break; |
328 | 326 | case 'blanks': |
329 | | - $this->mOptions['blanks'] = self::trueCheck ( $value ); |
| 327 | + $this->mOptions[$name] = self::parseBoolean( $value ); |
330 | 328 | break; |
331 | 329 | case 'outputseparator': |
332 | | - case 'separator': |
333 | | - $this->mOptions['outputseparator'] = self::trimString ( $value ); |
334 | | - break; |
335 | 330 | case 'lastseparator': |
336 | | - $this->mOptions['lastseparator'] = self::trimString ( $value ); |
337 | | - break; |
338 | 331 | case 'itemcover': |
339 | | - $this->mOptions['itemcover'] = self::trimString ( $value ); |
| 332 | + $this->mOptions[$name] = self::parseString( $value ); |
340 | 333 | break; |
341 | 334 | case 'fieldsperitem': |
342 | | - case 'itemsperitem': |
343 | | - $this->mOptions['fieldsperitem'] = self::numeralCheck ( $value ); |
| 335 | + $this->mOptions[$name] = self::parseNumeral( $value ); |
344 | 336 | break; |
345 | 337 | default: |
346 | 338 | # Wasn't an option after all |
— | — | @@ -347,22 +339,42 @@ |
348 | 340 | ? trim( $this->mFrame->expand( $arg ) ) |
349 | 341 | : $arg; |
350 | 342 | } |
| 343 | + return false; |
351 | 344 | } |
352 | 345 | |
353 | | - private static function numeralCheck ( $value, $default = 1 ) { |
354 | | - if ( is_numeric ( $value ) && $value > 0 ) { |
| 346 | + private static function parseOptionName( $value ) { |
| 347 | + |
| 348 | + static $magicWords = null; |
| 349 | + if ( $magicWords === null ) { |
| 350 | + $magicWords = new MagicWordArray( array( |
| 351 | + 'nll_blanks', 'nll_duplicates', |
| 352 | + 'nll_fieldsperitem', 'nll_itemcover', |
| 353 | + 'nll_lastseparator', 'nll_outputseparator' |
| 354 | + ) ); |
| 355 | + } |
| 356 | + |
| 357 | + if ( $name = $magicWords->matchStartToEnd( trim($value) ) ) { |
| 358 | + return str_replace( 'nll_', '', $name ); |
| 359 | + } |
| 360 | + |
| 361 | + return false; |
| 362 | + } |
| 363 | + |
| 364 | + |
| 365 | + private static function parseNumeral( $value, $default = 1 ) { |
| 366 | + if ( is_numeric( $value ) && $value > 0 ) { |
355 | 367 | return floor( $value ); # only integers |
356 | 368 | } |
357 | 369 | return $default; |
358 | 370 | } |
359 | 371 | |
360 | | - private static function trimString ( $value, $default = null ) { |
| 372 | + private static function parseString( $value, $default = null ) { |
361 | 373 | if ( $value !== '' ) |
362 | 374 | return $value; |
363 | 375 | return $default; |
364 | 376 | } |
365 | 377 | |
366 | | - private static function trueCheck ( $value ) { |
| 378 | + private static function parseBoolean( $value ) { |
367 | 379 | return in_array( $value, array( 1, true, '1', 'true' ), true ); |
368 | 380 | } |
369 | 381 | } |