Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
InsertablesAid.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Aid;
5
7
17 public function getData(): array {
18 // We need to get the primary group to get the correct file
19 // So $group can be different from $this->group
20 $group = $this->handle->getGroup();
21
22 // This was added later, so not all classes have it. In addition
23 // the message group class hierarchy doesn't lend itself easily
24 // to the user of interfaces for this purpose.
25 if ( !method_exists( $group, 'getInsertablesSuggester' ) ) {
26 throw new TranslationHelperException( 'Group does not have insertable suggesters' );
27 }
28
29 // @phan-suppress-next-line PhanUndeclaredMethod
30 $suggester = $group->getInsertablesSuggester();
31
32 // It is okay to return null suggester
33 if ( !$suggester ) {
34 throw new TranslationHelperException( 'Group does not have insertable suggesters' );
35 }
36
37 $insertables = $suggester->getInsertables( $this->dataProvider->getDefinition() );
38 $blob = [];
39 foreach ( $insertables as $insertable ) {
40 $displayText = $insertable->getDisplayText();
41
42 // The keys are used for de-duplication
43 $blob[$displayText] = [
44 'display' => $displayText,
45 'pre' => $insertable->getPreText(),
46 'post' => $insertable->getPostText(),
47 ];
48 }
49
50 $blob = array_values( $blob );
51 $blob['**'] = 'insertable';
52
53 return $blob;
54 }
55}
getData()
Translation aid class should implement this function.
Translation helpers can throw this exception when they cannot do anything useful with the current mes...