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] ) ) {
29 continue;
30 }
31
32 if ( $fallbackCode === $sourceLanguage ) {
33 continue;
34 }
35
36 $suggestions[] = [
37 'language' => $fallbackCode,
38 'value' => $translations[$fallbackCode],
39 ];
40 }
41
42 return $suggestions;
43 }
44
51 protected function getFallbacks( string $code ): array {
52 global $wgTranslateLanguageFallbacks;
53 $mwServices = MediaWikiServices::getInstance();
54
55 // User preference has the final say
56 $userOptionLookup = $mwServices->getUserOptionsLookup();
57 $preference = $userOptionLookup->getOption( $this->context->getUser(), 'translate-editlangs' );
58 if ( $preference !== 'default' ) {
59 $fallbacks = array_map( 'trim', explode( ',', $preference ) );
60 foreach ( $fallbacks as $k => $v ) {
61 if ( $v === $code ) {
62 unset( $fallbacks[$k] );
63 }
64 }
65
66 return $fallbacks;
67 }
68
69 // Global configuration settings
70 $fallbacks = [];
71 if ( isset( $wgTranslateLanguageFallbacks[$code] ) ) {
72 $fallbacks = (array)$wgTranslateLanguageFallbacks[$code];
73 }
74
75 $list = $mwServices->getLanguageFallback()->getAll( $code );
76 $fallbacks = array_merge( $list, $fallbacks );
77
78 return array_unique( $fallbacks );
79 }
80}
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.