-m
This commit is contained in:
@@ -36,7 +36,8 @@ final class LocaleSwitcher
|
||||
'UTF-8',
|
||||
);
|
||||
|
||||
$html = '<ul class="locale-switcher" role="list" aria-label="' . $ariaLabel . '">';
|
||||
$html = '<div class="locale-switcher-wrapper">';
|
||||
$html .= '<ul class="locale-switcher" role="list" aria-label="' . $ariaLabel . '">';
|
||||
foreach (Locale::SUPPORTED as $code) {
|
||||
$isCurrent = $code === $this->currentLocale;
|
||||
$name = htmlspecialchars(
|
||||
@@ -74,6 +75,53 @@ final class LocaleSwitcher
|
||||
}
|
||||
$html .= '</ul>';
|
||||
|
||||
// Mobile dropdown — compact single-trigger switcher for narrow viewports
|
||||
$currentName = htmlspecialchars(
|
||||
I18n::t('locale.' . $this->currentLocale, [], $this->currentLocale),
|
||||
ENT_QUOTES,
|
||||
'UTF-8',
|
||||
);
|
||||
$currentCode = htmlspecialchars($this->currentLocale, ENT_QUOTES, 'UTF-8');
|
||||
$currentFlag = self::flagSvg($this->currentLocale);
|
||||
$html .= '<details class="locale-switcher-mobile">';
|
||||
$html .= '<summary class="locale-switcher-mobile__trigger" aria-label="' . $ariaLabel . '">';
|
||||
$html .= '<span class="locale-switcher-mobile__current" lang="' . $currentCode . '">';
|
||||
$html .= $currentFlag;
|
||||
$html .= '<span class="locale-switcher-mobile__current-code">' . strtoupper($currentCode) . '</span>';
|
||||
$html .= '</span>';
|
||||
$html .= '<span class="locale-switcher-mobile__caret" aria-hidden="true">▾</span>';
|
||||
$html .= '</summary>';
|
||||
$html .= '<ul class="locale-switcher-mobile__menu" role="list">';
|
||||
foreach (Locale::SUPPORTED as $code) {
|
||||
$isCurrent = $code === $this->currentLocale;
|
||||
$name = htmlspecialchars(
|
||||
I18n::t('locale.' . $code, [], $this->currentLocale),
|
||||
ENT_QUOTES,
|
||||
'UTF-8',
|
||||
);
|
||||
$codeAttr = htmlspecialchars($code, ENT_QUOTES, 'UTF-8');
|
||||
$flag = self::flagSvg($code);
|
||||
|
||||
$html .= '<li>';
|
||||
if ($isCurrent) {
|
||||
$html .= '<span class="locale-switcher-mobile__option is-current" aria-current="true" lang="' . $codeAttr . '">'
|
||||
. $flag . '<span>' . $name . '</span></span>';
|
||||
} else {
|
||||
$url = '/locale?set=' . rawurlencode($code) . '&return=' . rawurlencode($path);
|
||||
$html .= '<a class="locale-switcher-mobile__option"'
|
||||
. ' href="' . $url . '"'
|
||||
. ' hreflang="' . $codeAttr . '"'
|
||||
. ' lang="' . $codeAttr . '"'
|
||||
. ' rel="alternate"'
|
||||
. '>'
|
||||
. $flag . '<span>' . $name . '</span></a>';
|
||||
}
|
||||
$html .= '</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
$html .= '</details>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user