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
{
21
private
$queries = [];
23
private
$aggregator;
24
25
public
function
setQueryAggregator(
QueryAggregator
$aggregator ):
void
{
26
$this->aggregator = $aggregator;
27
}
28
37
protected
function
storeQuery
(
38
TranslationWebService
$service,
39
string
$from,
40
string
$to,
41
string
$text
42
): void {
43
$queries = $service->getQueries( $text, $from, $to );
44
foreach
( $queries as $query ) {
45
$this->queries[] = [
46
'id'
=> $this->aggregator->addQuery( $query ),
47
'language'
=> $from,
48
'text'
=> $text,
49
'service'
=> $service,
50
];
51
}
52
}
53
61
protected
function
getQueryData
(): array {
62
foreach ( $this->queries as &$queryData ) {
63
$queryData[
'response'
] = $this->aggregator->getResponse( $queryData[
'id'
] );
64
unset( $queryData[
'id'
] );
65
}
66
67
return
$this->queries;
68
}
69
}
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:37
MediaWiki\Extension\Translate\TranslatorInterface\Aid\QueryAggregatorAwareTranslationAid\getQueryData
getQueryData()
Returns all stored queries.
Definition
QueryAggregatorAwareTranslationAid.php:61
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:24
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