summaryrefslogtreecommitdiff
blob: 1d327354c39bb525f7c7b587389120dd6b3357e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare( strict_types = 1 );

namespace MediaWiki\Extension\Translate\TranslatorInterface\Insertable;

/**
 * Insertables suggester for numerical parameters such as $1, $2, $3
 * @author Geoffrey Mon
 * @license GPL-2.0-or-later
 * @since 2020.12
 */
class NumericalParameterInsertablesSuggester implements InsertablesSuggester {
	public function getInsertables( string $text ): array {
		$insertables = [];

		// $1, $2, $3 etc.
		$matches = [];
		preg_match_all(
			'/\$\d+/',
			$text,
			$matches,
			PREG_SET_ORDER
		);
		$new = array_map( function ( $match ) {
			return new Insertable( $match[0], $match[0] );
		}, $matches );
		$insertables = array_merge( $insertables, $new );

		return $insertables;
	}
}

class_alias(
	NumericalParameterInsertablesSuggester::class,
	'\MediaWiki\Extensions\Translate\NumericalParameterInsertablesSuggester'
);