protected function preinit() { $code = $this->options->getLanguage(); global $wgTranslateTranslationServices; $config = $wgTranslateTranslationServices['tmserver']; $server = $config['server']; $port = $config['port']; $timeout = $config['timeout-sync']; $sourceLanguage = $this->group->getSourceLanguage(); $this->collection = $this->group->initCollection( $code ); $this->collection->setInfile( $this->group->load( $code ) ); $this->collection->filter( 'ignored' ); $this->collection->filter( 'optional' ); $this->collection->filter( 'translated' ); $this->collection->filter( 'fuzzy' ); $this->collection->loadTranslations(); $start = time(); foreach ( $this->collection->getMessageKeys() as $key ) { // Allow up to 10 seconds to search for suggestions. if ( time() - $start > 10 || TranslationHelpers::checkTranslationServiceFailure( 'tmserver' ) ) { unset( $this->collection[$key] ); continue; } $def = rawurlencode( $this->collection[$key]->definition() ); $url = "$server:$port/tmserver/$sourceLanguage/$code/unit/$def"; $suggestions = Http::get( $url, $timeout ); if ( $suggestions !== false ) { $suggestions = FormatJson::decode( $suggestions, true ); foreach ( $suggestions as $s ) { // We have a good suggestion, do not filter. if ( $s['quality'] > 0.80 ) { continue 2; } } } else { TranslationHelpers::reportTranslationServiceFailure( 'tmserver' ); } unset( $this->collection[$key] ); } }