25 global $wgTranslateDocumentationLanguageCode;
27 if ( $code === $wgTranslateDocumentationLanguageCode ) {
28 return 'nplurals=1; plural=0;';
31 $rulefile = __DIR__ .
'/../../data/plural-gettext.txt';
32 $rules = file_get_contents( $rulefile );
33 foreach ( explode(
"\n", $rules ) as $line ) {
34 if ( trim( $line ) ===
'' ) {
37 [ $rulecode, $rule ] = explode(
"\t", $line );
38 if ( $rulecode === $code ) {
141 $pre = preg_quote( self::PRE,
'/' );
142 $post = preg_quote( self::POST,
'/' );
144 [ $armouredText, $armourMap ] = self::armour( $text );
146 $ok = preg_match_all(
"/$pre(.*)$post/Us", $armouredText, $m );
147 if ( $ok ===
false ) {
151 $template = $armouredText;
154 foreach ( $m[0] as $instanceIndex => $instanceText ) {
155 $ph = TranslateUtils::getPlaceholder();
158 $pattern =
'/' . preg_quote( $instanceText,
'/' ) .
'/';
159 $template = preg_replace( $pattern, $ph, $template, 1 );
161 $instanceForms = explode(
'|', $m[ 1 ][ $instanceIndex ] );
162 foreach ( $instanceForms as $i => $v ) {
163 $instanceForms[ $i ] = self::unarmour( $v, $armourMap );
166 $instanceMap[$ph] = $instanceForms;
169 $template = self::unarmour( $template, $armourMap );
170 return [ $template, $instanceMap ];
181 public static function expandTemplate( $template, array $instanceMap, $expectedPluralCount ) {
183 for ( $formIndex = 0; $formIndex < $expectedPluralCount; $formIndex++ ) {
189 foreach ( $instanceMap as $ph => $instanceForms ) {
192 $replacement = $instanceForms[ $formIndex ] ??
'';
193 $form = str_replace( $ph, $replacement, $form );
196 $formArray[ $formIndex ] = $form;