Translate extension for MediaWiki
Loading...
Searching...
No Matches
QueryAggregatorAwareTranslationAid.php
1
<?php
2
declare( strict_types = 1 );
3
4
namespace
MediaWiki\Extension\Translate\TranslatorInterface\Aid;
5
6
use
MediaWiki\Extension\Translate\WebService\QueryAggregator
;
7
use
MediaWiki\Extension\Translate\WebService\QueryAggregatorAware
;
8
use
MediaWiki\Extension\Translate\WebService\TranslationWebService
;
9
17
abstract
class
QueryAggregatorAwareTranslationAid
18
extends
TranslationAid
19
implements
QueryAggregatorAware
20
{
22
private
$queries = [];
24
private
$aggregator;
25
26
public
function
setQueryAggregator(
QueryAggregator
$aggregator ):
void
{
27
$this->aggregator = $aggregator;
28
}
29
38
protected
function
storeQuery
(
39
TranslationWebService
$service,
40
string
$from,
41
string
$to,
42
string
$text
43
): void {
44
$queries = $service->getQueries( $text, $from, $to );
45
foreach
( $queries as $query ) {
46
$this->queries[] = [
47
'id'
=> $this->aggregator->addQuery( $query ),
48
'language'
=> $from,
49
'text'
=> $text,
50
'service'
=> $service,
51
];
52
}
53
}
54
62
protected
function
getQueryData
(): array {
63
foreach ( $this->queries as &$queryData ) {
64
$queryData[
'response'
] = $this->aggregator->getResponse( $queryData[
'id'
] );
65
unset( $queryData[
'id'
] );
66
}
67
68
return
$this->queries;
69
}
70
}
MediaWiki\Extension\Translate\TranslatorInterface\Aid\QueryAggregatorAwareTranslationAid
Helper class for translation aids that use web services.
Definition
QueryAggregatorAwareTranslationAid.php:20
MediaWiki\Extension\Translate\TranslatorInterface\Aid\QueryAggregatorAwareTranslationAid\storeQuery
storeQuery(TranslationWebService $service, string $from, string $to, string $text)
Stores a web service query for later execution.
Definition
QueryAggregatorAwareTranslationAid.php:38
MediaWiki\Extension\Translate\TranslatorInterface\Aid\QueryAggregatorAwareTranslationAid\getQueryData
getQueryData()
Returns all stored queries.
Definition
QueryAggregatorAwareTranslationAid.php:62
MediaWiki\Extension\Translate\TranslatorInterface\Aid\TranslationAid
Definition
TranslationAid.php:21
MediaWiki\Extension\Translate\WebService\QueryAggregator
Web service utility class.
Definition
QueryAggregator.php:17
MediaWiki\Extension\Translate\WebService\TranslationWebService
Definition
TranslationWebService.php:25
MediaWiki\Extension\Translate\WebService\QueryAggregatorAware
Interface for classes that want to use QueryAggregator.
Definition
QueryAggregatorAware.php:12
src
TranslatorInterface
Aid
QueryAggregatorAwareTranslationAid.php
Generated by
1.10.0