Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
QueryAggregatorAwareTranslationAid.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Aid;
5
9
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}
storeQuery(TranslationWebService $service, string $from, string $to, string $text)
Stores a web service query for later execution.
Interface for classes that want to use QueryAggregator.