mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
Merge "Check language fallbacks in isLanguageRequiringReplyIcon"
This commit is contained in:
commit
d4d595c1b8
|
@ -555,14 +555,14 @@
|
||||||
"description": "Override availability of DiscussionTools visual enhancements's reply buttons sub-feature. 'default', 'available', or 'unavailable'."
|
"description": "Override availability of DiscussionTools visual enhancements's reply buttons sub-feature. 'default', 'available', or 'unavailable'."
|
||||||
},
|
},
|
||||||
"DiscussionTools_visualenhancements_reply_icon_languages": {
|
"DiscussionTools_visualenhancements_reply_icon_languages": {
|
||||||
"value": [
|
"value": {
|
||||||
"ar",
|
"ar": true,
|
||||||
"zh",
|
"zh": true,
|
||||||
"yue",
|
"yue": true,
|
||||||
"ja",
|
"ja": true,
|
||||||
"nod"
|
"nod": true
|
||||||
],
|
},
|
||||||
"description": "A list of language codes which will receive an icon in their enhanced reply-button treatment, due to translation being very short (T323537).",
|
"description": "A dictionary of language codes which will receive an icon in their enhanced reply-button treatment, due to translation being very short (T323537). Language fallbacks will be checked unless a language is explicitly set to `false` (T352289). Normalized language codes are lower case.",
|
||||||
"merge_strategy": "provide_default"
|
"merge_strategy": "provide_default"
|
||||||
},
|
},
|
||||||
"DiscussionTools_visualenhancements_newsectionlink_enable": {
|
"DiscussionTools_visualenhancements_newsectionlink_enable": {
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace MediaWiki\Extension\DiscussionTools;
|
namespace MediaWiki\Extension\DiscussionTools;
|
||||||
|
|
||||||
|
use ConfigException;
|
||||||
use Html;
|
use Html;
|
||||||
use IContextSource;
|
use IContextSource;
|
||||||
use Language;
|
use Language;
|
||||||
|
@ -932,10 +933,40 @@ class CommentFormatter {
|
||||||
return $pout->getExtensionData( 'DiscussionTools-hasCommentsInLedeContent' ) === true;
|
return $pout->getExtensionData( 'DiscussionTools-hasCommentsInLedeContent' ) === true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isLanguageRequiringReplyIcon( Language $lang ): bool {
|
/**
|
||||||
$dtConfig = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'discussiontools' );
|
* Check if the language requires an icon for the reply button
|
||||||
|
*
|
||||||
|
* @param Language $userLang Language
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function isLanguageRequiringReplyIcon( Language $userLang ): bool {
|
||||||
|
$services = MediaWikiServices::getInstance();
|
||||||
|
|
||||||
|
$dtConfig = $services->getConfigFactory()->makeConfig( 'discussiontools' );
|
||||||
$languages = $dtConfig->get( 'DiscussionTools_visualenhancements_reply_icon_languages' );
|
$languages = $dtConfig->get( 'DiscussionTools_visualenhancements_reply_icon_languages' );
|
||||||
return in_array( $lang->getCode(), $languages, true );
|
|
||||||
|
if ( array_is_list( $languages ) ) {
|
||||||
|
// Detect legacy list format
|
||||||
|
throw new ConfigException(
|
||||||
|
'DiscussionTools_visualenhancements_reply_icon_languages must be an associative array'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// User language matched exactly and is explicitly set to true or false
|
||||||
|
if ( isset( $languages[ $userLang->getCode() ] ) ) {
|
||||||
|
return (bool)$languages[ $userLang->getCode() ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check fallback languages
|
||||||
|
$fallbackLanguages = $userLang->getFallbackLanguages();
|
||||||
|
foreach ( $fallbackLanguages as $fallbackLangauge ) {
|
||||||
|
if ( isset( $languages[ $fallbackLangauge ] ) ) {
|
||||||
|
return (bool)$languages[ $fallbackLangauge ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Language not listed, default is to show no icon
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue