blob: e2b51ee7bc44a6fe8c9994edeaf89a626a6b81b5 (
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<?php
/**
* Translation aid provider.
*
* @file
* @author Niklas Laxström
* @license GPL-2.0-or-later
*/
/**
* Translation aid which suggests insertables. Insertable is a string that
* usually does not need translation and is difficult to type manually.
*
* @ingroup TranslationAids
* @since 2013.09
*/
class InsertablesAid extends TranslationAid {
public function getData() {
// We need to get the primary group to get the correct file
// So $group can be different from $this->group
$group = $this->handle->getGroup();
// This was added later, so not all classes have it. In addition
// the message group class hierarche doesn't lend itself easily
// to the user of interfaces for this purpose.
if ( !is_callable( [ $group, 'getInsertablesSuggester' ] ) ) {
throw new TranslationHelperException( 'Group does not have a suggester' );
}
// @phan-suppress-next-line PhanUndeclaredMethod
$suggester = $group->getInsertablesSuggester();
// It is okay to return null suggester
if ( !$suggester ) {
throw new TranslationHelperException( 'Group does not have a suggester' );
}
$insertables = $suggester->getInsertables( $this->dataProvider->getDefinition() );
$blob = [];
foreach ( $insertables as $insertable ) {
$displayText = $insertable->getDisplayText();
// The keys are used for de-duplication
$blob[$displayText] = [
'display' => $displayText,
'pre' => $insertable->getPreText(),
'post' => $insertable->getPostText(),
];
}
$blob = array_values( $blob );
$blob['**'] = 'insertable';
return $blob;
}
}
|