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{
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}
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.