18 public function populateQueries():
void {
19 $definition = $this->dataProvider->getDefinition();
20 $translations = $this->dataProvider->getGoodTranslations();
21 $sourceLanguage = $this->group->getSourceLanguage();
22 $targetLanguage = $this->handle->getCode();
24 if ( trim( $definition ) ===
'' ) {
28 foreach ( $this->getWebServices() as $service ) {
29 if ( $service->checkTranslationServiceFailure() ) {
34 if ( $service->isSupportedLanguagePair( $sourceLanguage, $targetLanguage ) ) {
35 $this->
storeQuery( $service, $sourceLanguage, $targetLanguage, $definition );
41 foreach ( $translations as $alternateSourceLanguage => $text ) {
42 if ( !$service->isSupportedLanguagePair( $alternateSourceLanguage, $targetLanguage ) ) {
46 $this->
storeQuery( $service, $alternateSourceLanguage, $targetLanguage, $text );
56 $suggestions = [
'**' =>
'suggestion' ];
59 $suggestions[] = $this->formatSuggestion( $queryData );
62 return array_filter( $suggestions );
65 protected function formatSuggestion( array $queryData ): ?array {
66 $service = $queryData[
'service'];
67 $response = $queryData[
'response'];
68 $sourceLanguage = $queryData[
'language'];
69 $sourceText = $queryData[
'text'];
71 $result = $service->getResultData( $response );
72 if ( $result ===
null ) {
78 'service' => $service->getName(),
79 'source_language' => $sourceLanguage,
80 'source' => $sourceText,
85 private function getWebServices(): array {
86 global $wgTranslateTranslationServices;
89 foreach ( $wgTranslateTranslationServices as $name => $config ) {
90 $service = TranslationWebService::factory( $name, $config );
91 if ( !$service || $service->getType() !==
'mt' ) {
95 $services[$name] = $service;