Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
CurrentTranslationAid
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 getData
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Aid;
5
6use MediaWiki\Extension\Translate\MessageLoading\MessageHandle;
7use MediaWiki\Extension\Translate\Services;
8use MediaWiki\Extension\Translate\Utilities\Utilities;
9
10/**
11 * Translation aid that provides the current saved translation.
12 * @author Niklas Laxström
13 * @license GPL-2.0-or-later
14 * @since 2013-01-01
15 * @ingroup TranslationAids
16 */
17class CurrentTranslationAid extends TranslationAid {
18    public function getData(): array {
19        $title = $this->handle->getTitle();
20        $translation = Utilities::getMessageContent(
21            $this->handle->getKey(),
22            $this->handle->getCode(),
23            $title->getNamespace()
24        );
25
26        Services::getInstance()->getHookRunner()
27            ->onTranslatePrefillTranslation( $translation, $this->handle );
28        // If we have still no translation, use the empty string so that
29        // string handler functions don't error out on PHP 8.1+
30        $translation ??= '';
31        $fuzzy = MessageHandle::hasFuzzyString( $translation ) || $this->handle->isFuzzy();
32        $translation = str_replace( TRANSLATE_FUZZY, '', $translation );
33
34        return [
35            'language' => $this->handle->getCode(),
36            'fuzzy' => $fuzzy,
37            'value' => $translation,
38        ];
39    }
40}