Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F6066620
InOtherLanguagesAid.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
InOtherLanguagesAid.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
MediaWiki\Extension\Translate\TranslatorInterface\Aid
;
use
MediaWiki\MediaWikiServices
;
/**
* Translation aid that provides the "in other languages" suggestions.
* @author Niklas Laxström
* @license GPL-2.0-or-later
* @since 2013-01-01
* @ingroup TranslationAids
*/
class
InOtherLanguagesAid
extends
TranslationAid
{
public
function
getData
():
array
{
$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
$fallbackCode
)
{
if
(
!
isset
(
$translations
[
$fallbackCode
]
)
||
$fallbackCode
===
$sourceLanguage
)
{
continue
;
}
$suggestions
[]
=
[
'language'
=>
$fallbackCode
,
'value'
=>
$translations
[
$fallbackCode
],
];
}
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
(
string
$code
):
array
{
global
$wgTranslateLanguageFallbacks
;
$mwServices
=
MediaWikiServices
::
getInstance
();
// User preference has the final say
$userOptionLookup
=
$mwServices
->
getUserOptionsLookup
();
$preference
=
$userOptionLookup
->
getOption
(
$this
->
context
->
getUser
(),
'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
=
$mwServices
->
getLanguageFallback
()->
getAll
(
$code
);
$fallbacks
=
array_merge
(
$list
,
$fallbacks
);
return
array_unique
(
$fallbacks
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Oct 5 2026, 04:51 (6 w, 7 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
21/ad/54ef4226cedd703a46ee80ddbaad
Default Alt Text
InOtherLanguagesAid.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment