diff options
Diffstat (limited to 'www/wiki/extensions/Translate/translationaids/InOtherLanguagesAid.php')
-rw-r--r-- | www/wiki/extensions/Translate/translationaids/InOtherLanguagesAid.php | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/www/wiki/extensions/Translate/translationaids/InOtherLanguagesAid.php b/www/wiki/extensions/Translate/translationaids/InOtherLanguagesAid.php new file mode 100644 index 00000000..41570860 --- /dev/null +++ b/www/wiki/extensions/Translate/translationaids/InOtherLanguagesAid.php @@ -0,0 +1,81 @@ +<?php +/** + * Translation aid provider. + * + * @file + * @author Niklas Laxström + * @copyright Copyright © 2012-2013, Niklas Laxström + * @license GPL-2.0-or-later + */ + +/** + * Translation aid which gives the "in other languages" suggestions. + * + * @ingroup TranslationAids + * @since 2013-01-01 + */ +class InOtherLanguagesAid extends TranslationAid { + public function getData() { + $suggestions = [ + '**' => 'suggestion', + ]; + + // Fuzzy translations are not included in these + $translations = $this->dataProvider->getGoodTranslations(); + $code = $this->handle->getCode(); + + $sourceLanguage = $this->handle->getGroup()->getSourceLanguage(); + + foreach ( $this->getFallbacks( $code ) as $fbcode ) { + if ( !isset( $translations[$fbcode] ) ) { + continue; + } + + if ( $fbcode === $sourceLanguage ) { + continue; + } + + $suggestions[] = [ + 'language' => $fbcode, + 'value' => $translations[$fbcode], + ]; + } + + return $suggestions; + } + + /** + * Get the languages for "in other languages". That would be translation + * assistant languages with defined language fallbacks additionally. + * @param string $code + * @return string[] List of language codes + */ + protected function getFallbacks( $code ) { + global $wgTranslateLanguageFallbacks; + + // User preference has the final say + $preference = $this->context->getUser()->getOption( 'translate-editlangs' ); + if ( $preference !== 'default' ) { + $fallbacks = array_map( 'trim', explode( ',', $preference ) ); + foreach ( $fallbacks as $k => $v ) { + if ( $v === $code ) { + unset( $fallbacks[$k] ); + } + } + + return $fallbacks; + } + + // Global configuration settings + $fallbacks = []; + if ( isset( $wgTranslateLanguageFallbacks[$code] ) ) { + $fallbacks = (array)$wgTranslateLanguageFallbacks[$code]; + } + + $list = Language::getFallbacksFor( $code ); + array_pop( $list ); // Get 'en' away from the end + $fallbacks = array_merge( $list, $fallbacks ); + + return array_unique( $fallbacks ); + } +} |