24 global $wgTranslateDocumentationLanguageCode;
26 if ( $code === $wgTranslateDocumentationLanguageCode ) {
27 return 'nplurals=1; plural=0;';
30 $rulefile = __DIR__ .
'/../../data/plural-gettext.txt';
31 $rules = file_get_contents( $rulefile );
32 foreach ( explode(
"\n", $rules ) as $line ) {
33 if ( trim( $line ) ===
'' ) {
36 [ $rulecode, $rule ] = explode(
"\t", $line );
37 if ( $rulecode === $code ) {
140 $pre = preg_quote( self::PRE,
'/' );
141 $post = preg_quote( self::POST,
'/' );
143 [ $armouredText, $armourMap ] = self::armour( $text );
145 $ok = preg_match_all(
"/$pre(.*)$post/Us", $armouredText, $m );
146 if ( $ok ===
false ) {
150 $template = $armouredText;
153 foreach ( $m[0] as $instanceIndex => $instanceText ) {
157 $pattern =
'/' . preg_quote( $instanceText,
'/' ) .
'/';
158 $template = preg_replace( $pattern, $ph, $template, 1 );
160 $instanceForms = explode(
'|', $m[ 1 ][ $instanceIndex ] );
161 foreach ( $instanceForms as $i => $v ) {
162 $instanceForms[ $i ] = self::unarmour( $v, $armourMap );
165 $instanceMap[$ph] = $instanceForms;
168 $template = self::unarmour( $template, $armourMap );
169 return [ $template, $instanceMap ];
180 public static function expandTemplate( $template, array $instanceMap, $expectedPluralCount ) {
182 for ( $formIndex = 0; $formIndex < $expectedPluralCount; $formIndex++ ) {
188 foreach ( $instanceMap as $ph => $instanceForms ) {
191 $replacement = $instanceForms[ $formIndex ] ??
'';
192 $form = str_replace( $ph, $replacement, $form );
195 $formArray[ $formIndex ] = $form;