Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
TranslationAid
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getData
n/a
0 / 0
n/a
0 / 0
0
 getTypes
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Aid;
5
6use IContextSource;
7use MediaWiki\Extension\Translate\MessageLoading\MessageHandle;
8use MediaWiki\Extension\Translate\TranslatorInterface\TranslationHelperException;
9use MessageGroup;
10
11/**
12 * Multipurpose class for translation aids:
13 *  - interface for translation aid classes
14 *  - listing of available translation aids
15 *
16 * @defgroup TranslationAids Translation Aids
17 * @author Niklas Laxström
18 * @license GPL-2.0-or-later
19 * @since 2013-01-01
20 */
21abstract class TranslationAid {
22    /** @var MessageGroup */
23    protected $group;
24    /** @var MessageHandle */
25    protected $handle;
26    /** @var IContextSource */
27    protected $context;
28    /** @var TranslationAidDataProvider */
29    protected $dataProvider;
30
31    public function __construct(
32        MessageGroup $group,
33        MessageHandle $handle,
34        IContextSource $context,
35        TranslationAidDataProvider $dataProvider
36    ) {
37        $this->group = $group;
38        $this->handle = $handle;
39        $this->context = $context;
40        $this->dataProvider = $dataProvider;
41    }
42
43    /**
44     * Translation aid class should implement this function. Return value should
45     * be an array with keys and values. Because these are used in the MediaWiki
46     * API, lists (numeric keys) should have key '**' set to element name that
47     * describes the list values. For example if the translation aid provides
48     * translation suggestions, it would return an array which has key '**' set
49     * to 'suggestion' and then list of arrays, each containing fields for the
50     * information of the suggestions. See InOtherLanguagesAid for example.
51     *
52     * @throws TranslationHelperException Used to signal unexpected errors to aid
53     *  debugging
54     * @return array
55     */
56    abstract public function getData(): array;
57
58    /**
59     * List of available message types mapped to the classes
60     * implementing them.
61     *
62     * @return array
63     */
64    public static function getTypes(): array {
65        return [
66            'groups' => GroupsAid::class,
67            'definition' => MessageDefinitionAid::class,
68            'translation' => CurrentTranslationAid::class,
69            'inotherlanguages' => InOtherLanguagesAid::class,
70            'documentation' => DocumentationAid::class,
71            'mt' => MachineTranslationAid::class,
72            'definitiondiff' => UpdatedDefinitionAid::class,
73            'ttmserver' => TTMServerAid::class,
74            'support' => SupportAid::class,
75            'gettext' => GettextDocumentationAid::class,
76            'insertables' => InsertablesAid::class,
77            'editsummaries' => EditSummariesAid::class,
78        ];
79    }
80}