r59525 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59524‎ | r59525 | r59526 >
Date:19:54, 28 November 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
Possible fix
Modified paths:
  • /trunk/extensions/Translate/ffs/Gettext.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/ffs/Gettext.php
@@ -1,6 +1,8 @@
22 <?php
33 if ( !defined( 'MEDIAWIKI' ) ) die();
44
 5+class GettextPluralException extends MwExceptipn {}
 6+
57 class GettextFormatReader extends SimpleFormatReader {
68 protected $pot = false;
79 public function setPotMode( $value ) {
@@ -226,9 +228,13 @@
227229 $output[] = 'msgid ' . $this->escape( $forms[0] );
228230 $output[] = 'msgid_plural ' . $this->escape( $forms[1] );
229231
230 - $forms = $this->splitPlural( $msgstr, $pluralForms );
231 - foreach( $forms as $index => $form ) {
232 - $output[] = "msgstr[$index] " . $this->escape( $form );
 232+ try {
 233+ $forms = $this->splitPlural( $msgstr, $pluralForms );
 234+ foreach( $forms as $index => $form ) {
 235+ $output[] = "msgstr[$index] " . $this->escape( $form );
 236+ }
 237+ } catch ( GettextPluralException $e ) {
 238+ $output[] = "# Plural problem";
233239 }
234240 } else {
235241 $output[] = 'msgid ' . $this->escape( $msgid );
@@ -253,14 +259,14 @@
254260 return $text;
255261 } elseif( !$forms ) {
256262 $forms = (int) $forms;
257 - throw new MWException( "Don't know how to split $text into $forms forms" );
 263+ throw new GettextPluralException( "Don't know how to split $text into $forms forms" );
258264 }
259265
260266 $splitPlurals = array();
261267 for ( $i = 0; $i < $forms; $i++ ) {
262268 $plurals = array();
263269 $match = preg_match_all( '/{{PLURAL:GETTEXT\|(.*)}}/iU', $text, $plurals );
264 - if ( !$match ) throw new MWException( "Failed to parse plural for: $text" );
 270+ if ( !$match ) throw new GettextPluralException( "Failed to parse plural for: $text" );
265271 $pluralForm = $text;
266272 foreach ( $plurals[0] as $index => $definition ) {
267273 $parsedFormsArray = explode( '|', $plurals[1][$index] );

Follow-up revisions

RevisionCommit summaryAuthorDate
r59528Fix fatal from r59525siebrand20:13, 28 November 2009

Status & tagging log