Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
MediaWikiInsertablesSuggester.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;
5
13 public function getInsertables( string $text ): array {
14 $insertables = [];
15
16 $matches = [];
17 // MediaWiki apihelp messages often have parameters like $1user, which should
18 // be unchanged in translation.
19 preg_match_all( '/\$(1[a-z]+|[0-9]+)/', $text, $matches, PREG_SET_ORDER );
20 $new = array_map( static function ( $match ) {
21 return new Insertable( $match[0], $match[0] );
22 }, $matches );
23 $insertables = array_merge( $insertables, $new );
24
25 $matches = [];
26 preg_match_all(
27 '/({{((?:PLURAL|GENDER|GRAMMAR):[^|]*)\|).*?(}})/i',
28 $text,
29 $matches,
30 PREG_SET_ORDER
31 );
32 $new = array_map( static function ( $match ) {
33 return new Insertable( $match[2], $match[1], $match[3] );
34 }, $matches );
35 $insertables = array_merge( $insertables, $new );
36
37 return array_merge(
38 $insertables,
39 ( new HtmlTagInsertablesSuggester() )->getInsertables( $text )
40 );
41 }
42}
Insertable is a string that usually does not need translation and is difficult to type manually.