diff options
Diffstat (limited to 'MLEB/Translate/src/TranslatorInterface/Aid/CurrentTranslationAid.php')
-rw-r--r-- | MLEB/Translate/src/TranslatorInterface/Aid/CurrentTranslationAid.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/MLEB/Translate/src/TranslatorInterface/Aid/CurrentTranslationAid.php b/MLEB/Translate/src/TranslatorInterface/Aid/CurrentTranslationAid.php new file mode 100644 index 00000000..9ed3f761 --- /dev/null +++ b/MLEB/Translate/src/TranslatorInterface/Aid/CurrentTranslationAid.php @@ -0,0 +1,36 @@ +<?php +declare( strict_types = 1 ); + +namespace MediaWiki\Extension\Translate\TranslatorInterface\Aid; + +use Hooks; +use MessageHandle; +use TranslateUtils; + +/** + * Translation aid that provides the current saved translation. + * @author Niklas Laxström + * @license GPL-2.0-or-later + * @since 2013-01-01 + * @ingroup TranslationAids + */ +class CurrentTranslationAid extends TranslationAid { + public function getData(): array { + $title = $this->handle->getTitle(); + $translation = TranslateUtils::getMessageContent( + $this->handle->getKey(), + $this->handle->getCode(), + $title->getNamespace() + ); + + Hooks::run( 'TranslatePrefillTranslation', [ &$translation, $this->handle ] ); + $fuzzy = MessageHandle::hasFuzzyString( $translation ) || $this->handle->isFuzzy(); + $translation = str_replace( TRANSLATE_FUZZY, '', $translation ); + + return [ + 'language' => $this->handle->getCode(), + 'fuzzy' => $fuzzy, + 'value' => $translation, + ]; + } +} |