Merge "Change ULS label for sticky header when 0 Languages available."

This commit is contained in:
jenkins-bot 2022-08-30 21:45:58 +00:00 committed by Gerrit Code Review
commit 62c0b80d4f
1 changed files with 20 additions and 17 deletions

View File

@ -644,16 +644,25 @@ abstract class SkinVector extends SkinMustache {
} }
/** /**
* Returns ULS button label within the context of the translated message taking a placeholder. * Get the ULS button label, accounting for the number of available
* languages.
* *
* @param string $message * @return array
* @param int $count
* @return string
*/ */
private function getULSLabel( string $message, int $count ): string { private function getULSLabels(): array {
return $this->msg( $message ) $numLanguages = count( $this->getLanguagesCached() );
->numParams( $count )
->escaped(); if ( $numLanguages === 0 ) {
return [
'label' => $this->msg( 'vector-no-language-button-label' )->text(),
'aria-label' => $this->msg( 'vector-no-language-button-aria-label' )->text()
];
} else {
return [
'label' => $this->msg( 'vector-language-button-label' )->numParams( $numLanguages )->escaped(),
'aria-label' => $this->msg( 'vector-language-button-aria-label' )->numParams( $numLanguages )->escaped()
];
}
} }
/** /**
@ -687,7 +696,7 @@ abstract class SkinVector extends SkinMustache {
'class' => 'mw-interlanguage-selector', 'class' => 'mw-interlanguage-selector',
'is-quiet' => true, 'is-quiet' => true,
'tabindex' => '-1', 'tabindex' => '-1',
'label' => $this->getULSLabel( 'vector-language-button-label', $numLanguages ), 'label' => $this->getULSLabels()[ 'label' ],
'html-vector-button-icon' => Hooks::makeIcon( 'wikimedia-language' ), 'html-vector-button-icon' => Hooks::makeIcon( 'wikimedia-language' ),
'event' => 'ui.dropdown-p-lang-btn-sticky-header' 'event' => 'ui.dropdown-p-lang-btn-sticky-header'
]; ];
@ -703,14 +712,8 @@ abstract class SkinVector extends SkinMustache {
$languageButtonData = [ $languageButtonData = [
'id' => 'p-lang-btn', 'id' => 'p-lang-btn',
// No languages present for the article. 'label' => $this->getULSLabels()['label'],
// But the page can show languages if there were languages. 'aria-label' => $this->getULSLabels()['aria-label'],
'label' => $numLanguages === 0 ?
$this->msg( 'vector-no-language-button-label' )->text() :
$this->getULSLabel( 'vector-language-button-label', $numLanguages ),
'aria-label' => $numLanguages === 0 ?
$this->msg( 'vector-no-language-button-aria-label' )->text() :
$this->getULSLabel( 'vector-language-button-aria-label', $numLanguages ),
// ext.uls.interface attaches click handler to this selector. // ext.uls.interface attaches click handler to this selector.
'checkbox-class' => ' mw-interlanguage-selector ', 'checkbox-class' => ' mw-interlanguage-selector ',
'icon' => 'language-progressive', 'icon' => 'language-progressive',