Make WordPress Core

Ticket #4005: gettext-plural-forms.patch

File gettext-plural-forms.patch, 1.0 KB (added by moeffju, 18 years ago)

Patch against php-gettext 1.0.7 to fix plural forms parsing

  • gettext.php

    old new  
    283283        $expr = $regs[1];
    284284      else
    285285        $expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
    286       $this->pluralheader = $expr;
     286
     287      // sanitize
     288      $expr = preg_replace(
     289        '@[^a-zA-Z0-9_:;\(\)\?\|\&=!<>+*/\%-]@',
     290        '',
     291        $expr
     292      );
     293     
     294      // add parens
     295      // important since PHP's ternary evaluates from left to right
     296      $expr.= ';';
     297      $res= '';
     298      $p= 0;
     299      for ($i= 0; $i < strlen($expr); $i++) {
     300        $ch= $expr[$i];
     301        switch ($ch) {
     302          case '?':
     303            $res.= ' ? (';
     304            $p++;
     305            break;
     306          case ':':
     307            $res.= ') : (';
     308            break;
     309          case ';':
     310            $res.= str_repeat( ')', $p) . ';';
     311            $p= 0;
     312            break;
     313          default:
     314            $res.= $ch;
     315        }
     316      }
     317     
     318      $this->pluralheader = $res;
    287319    }
    288320    return $this->pluralheader;
    289321  }