r36311 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36310‎ | r36311 | r36312 >
Date:20:56, 15 June 2008
Author:nikerabbit
Status:old
Tags:
Comment:
* Working on plural support
Modified paths:
  • /trunk/extensions/Translate/ffs/Gettext.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/ffs/Gettext.php
@@ -24,10 +24,11 @@
2525 $data = file_get_contents( $this->filename );
2626 $data = str_replace( "\r\n", "\n", $data );
2727
 28+ $pluralForms = false;
 29+
2830 $matches = array();
2931 if ( preg_match( '/X-Language-Code:\s+([a-zA-Z-_]+)/', $data, $matches ) ) {
3032 $code = $matches[1];
31 - } else {
3233 }
3334
3435 if ( preg_match( '/X-Message-Group:\s+([a-zA-Z0-9-_]+)/', $data, $matches ) ) {
@@ -37,6 +38,10 @@
3839 $useCtxtAsKey = false;
3940 }
4041
 42+ if ( preg_match( '/Plural-Forms:\s+nplurals=([0-9]+)/', $data, $matches ) ) {
 43+ $pluralForms = $matches[1];
 44+ }
 45+
4146 $poformat = '".*"\n?(^".*"$\n?)*';
4247 $quotePattern = '/(^"|"$\n?)/m';
4348
@@ -74,15 +79,42 @@
7580 continue;
7681 }
7782
 83+ $pluralMessage = false;
7884 $matches = array();
79 - if ( preg_match( "/^msgstr\s($poformat)/mx", $section, $matches ) ) {
80 - // Remove quoting
81 - $item['str'] = preg_replace( $quotePattern, '', $matches[1] );
82 - // Restore new lines and remove quoting
83 - #$translation = stripcslashes( $translation );
 85+ if ( preg_match( "/^msgid_plural\s($poformat)/mx", $section, $matches ) ) {
 86+ $pluralMessage = true;
 87+ $plural = preg_replace( $quotePattern, '', $matches[1] );;
 88+ $item['id'] = "{{PLURAL:GETTEXT|{$item['id']}|$plural}}";
 89+
 90+ var_dump( $item['id'] );
 91+ }
 92+
 93+ if ( $pluralMessage ) {
 94+
 95+ $actualForms = array();
 96+ for ( $i = 0; $i < $pluralForms; $i++ ) {
 97+ $matches = array();
 98+ if ( preg_match( "/^msgstr\[$i\]\s($poformat)/mx", $section, $matches ) ) {
 99+ $actualForms[] = preg_replace( $quotePattern, '', $matches[1] );
 100+ } else {
 101+ throw new MWException( "Plural not found, expecting $i" );
 102+ }
 103+ }
 104+
 105+ $item['str'] = '{{PLURAL:GETTEXT|' . implode( '|', $actualForms ) . '}}';
 106+ var_dump( $item['str'] );
84107 } else {
85 - #echo "Translation not found!\n";
86 - continue;
 108+
 109+ $matches = array();
 110+ if ( preg_match( "/^msgstr\s($poformat)/mx", $section, $matches ) ) {
 111+ // Remove quoting
 112+ $item['str'] = preg_replace( $quotePattern, '', $matches[1] );
 113+ // Restore new lines and remove quoting
 114+ #$translation = stripcslashes( $translation );
 115+ } else {
 116+ #echo "Translation not found!\n";
 117+ continue;
 118+ }
87119 }
88120
89121 // Parse flags

Status & tagging log