summaryrefslogtreecommitdiff
blob: 1b715643c365dc92f746b68a0fa534afdce5164e (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
 * Translation aid code.
 *
 * @file
 * @author Niklas Laxström
 * @license GPL-2.0-or-later
 */

/**
 * Multipurpose class for translation aids:
 *  - interface for translation aid classes
 *  - listing of available translation aids
 *
 * @defgroup TranslationAids Translation Aids
 * @since 2013-01-01
 */
abstract class TranslationAid {
	/** @var MessageGroup */
	protected $group;
	/** @var MessageHandle */
	protected $handle;
	/** @var IContextSource */
	protected $context;
	/** @var TranslationAidDataProvider */
	protected $dataProvider;

	public function __construct(
		MessageGroup $group,
		MessageHandle $handle,
		IContextSource $context,
		TranslationAidDataProvider $dataProvider
	) {
		$this->group = $group;
		$this->handle = $handle;
		$this->context = $context;
		$this->dataProvider = $dataProvider;
	}

	/**
	 * Translation aid class should implement this function. Return value should
	 * be an array with keys and values. Because these are used in the MediaWiki
	 * API, lists (numeric keys) should have key '**' set to element name that
	 * describes the list values. For example if the translation aid provides
	 * translation suggestions, it would return an array which has key '**' set
	 * to 'suggestion' and then list of arrays, each containing fields for the
	 * information of the suggestions. See InOtherLanguagesAid for example.
	 *
	 * @throws TranslationHelperException Used to signal unexpected errors to aid
	 *  debugging
	 * @return array
	 */
	abstract public function getData();

	/**
	 * List of available message types mapped to the classes
	 * implementing them.
	 *
	 * @return array
	 */
	public static function getTypes() {
		$types = [
			'definition' => 'MessageDefinitionAid',
			'translation' => 'CurrentTranslationAid',
			'inotherlanguages' => 'InOtherLanguagesAid',
			'documentation' => 'DocumentationAid',
			'mt' => 'MachineTranslationAid',
			'definitiondiff' => 'UpdatedDefinitionAid',
			'ttmserver' => 'TTMServerAid',
			'support' => 'SupportAid',
			'gettext' => 'GettextDocumentationAid',
			'insertables' => 'InsertablesAid',
		];

		return $types;
	}
}