Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
InOtherLanguagesAid.php
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\TranslatorInterface\Aid;
5
6use MediaWiki\MediaWikiServices;
7
16 public function getData(): array {
17 $suggestions = [
18 '**' => 'suggestion',
19 ];
20
21 // Fuzzy translations are not included in these
22 $translations = $this->dataProvider->getGoodTranslations();
23 $code = $this->handle->getCode();
24
25 $sourceLanguage = $this->handle->getGroup()->getSourceLanguage();
26
27 foreach ( $this->getFallbacks( $code ) as $fallbackCode ) {
28 if ( !isset( $translations[$fallbackCode] ) || $fallbackCode === $sourceLanguage ) {
29 continue;
30 }
31
32 $suggestions[] = [
33 'language' => $fallbackCode,
34 'value' => $translations[$fallbackCode],
35 ];
36 }
37
38 return $suggestions;
39 }
40
47 protected function getFallbacks( string $code ): array {
48 global $wgTranslateLanguageFallbacks;
49 $mwServices = MediaWikiServices::getInstance();
50
51 // User preference has the final say
52 $userOptionLookup = $mwServices->getUserOptionsLookup();
53 $preference = $userOptionLookup->getOption( $this->context->getUser(), 'translate-editlangs' );
54 if ( $preference !== 'default' ) {
55 $fallbacks = array_map( 'trim', explode( ',', $preference ) );
56 foreach ( $fallbacks as $k => $v ) {
57 if ( $v === $code ) {
58 unset( $fallbacks[$k] );
59 }
60 }
61
62 return $fallbacks;
63 }
64
65 // Global configuration settings
66 $fallbacks = [];
67 if ( isset( $wgTranslateLanguageFallbacks[$code] ) ) {
68 $fallbacks = (array)$wgTranslateLanguageFallbacks[$code];
69 }
70
71 $list = $mwServices->getLanguageFallback()->getAll( $code );
72 $fallbacks = array_merge( $list, $fallbacks );
73
74 return array_unique( $fallbacks );
75 }
76}
Translation aid that provides the "in other languages" suggestions.
getFallbacks(string $code)
Get the languages for "in other languages".
getData()
Translation aid class should implement this function.