Index: trunk/extensions/Translate/ffs/Gettext.php |
— | — | @@ -24,10 +24,11 @@ |
25 | 25 | $data = file_get_contents( $this->filename ); |
26 | 26 | $data = str_replace( "\r\n", "\n", $data ); |
27 | 27 | |
| 28 | + $pluralForms = false; |
| 29 | + |
28 | 30 | $matches = array(); |
29 | 31 | if ( preg_match( '/X-Language-Code:\s+([a-zA-Z-_]+)/', $data, $matches ) ) { |
30 | 32 | $code = $matches[1]; |
31 | | - } else { |
32 | 33 | } |
33 | 34 | |
34 | 35 | if ( preg_match( '/X-Message-Group:\s+([a-zA-Z0-9-_]+)/', $data, $matches ) ) { |
— | — | @@ -37,6 +38,10 @@ |
38 | 39 | $useCtxtAsKey = false; |
39 | 40 | } |
40 | 41 | |
| 42 | + if ( preg_match( '/Plural-Forms:\s+nplurals=([0-9]+)/', $data, $matches ) ) { |
| 43 | + $pluralForms = $matches[1]; |
| 44 | + } |
| 45 | + |
41 | 46 | $poformat = '".*"\n?(^".*"$\n?)*'; |
42 | 47 | $quotePattern = '/(^"|"$\n?)/m'; |
43 | 48 | |
— | — | @@ -74,15 +79,42 @@ |
75 | 80 | continue; |
76 | 81 | } |
77 | 82 | |
| 83 | + $pluralMessage = false; |
78 | 84 | $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'] ); |
84 | 107 | } 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 | + } |
87 | 119 | } |
88 | 120 | |
89 | 121 | // Parse flags |