lang_swither.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Footer language switcher. Hidden when fewer than two language modules exist.
  4. */
  5. if (empty($aLangs) || count($aLangs) < 2)
  6. return;
  7. if (!function_exists('bx_install_lang_url')) {
  8. function bx_install_lang_url($sCode)
  9. {
  10. $a = array();
  11. if (!empty($_GET['action']))
  12. $a['action'] = $_GET['action'];
  13. $a['lang'] = $sCode;
  14. return '?' . http_build_query($a);
  15. }
  16. }
  17. $sTranslateSvg = '<svg class="bx-install-lang-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m5 8 6 6"/><path d="m4 14 6-6 2-3"/><path d="M2 5h12"/><path d="M7 2h1"/><path d="m22 22-5-10-5 10"/><path d="M14 18h6"/></svg>';
  18. ?>
  19. <details class="bx-install-lang">
  20. <summary class="bx-install-lang-trigger">
  21. <?php echo $sTranslateSvg; ?>
  22. <span class="bx-install-lang-current"><?php echo bx_html_attribute($sLangTitle); ?></span>
  23. </summary>
  24. <div class="bx-install-lang-menu" role="menu">
  25. <?php foreach ($aLangs as $aLang): ?>
  26. <a role="menuitem" class="bx-install-lang-item<?php echo ($aLang['code'] === $sLang) ? ' is-selected' : ''; ?>" href="<?php echo bx_html_attribute(bx_install_lang_url($aLang['code'])); ?>">
  27. <span class="bx-install-lang-badge"><?php echo $sTranslateSvg; ?></span>
  28. <span><?php echo bx_html_attribute($aLang['title']); ?></span>
  29. </a>
  30. <?php endforeach; ?>
  31. </div>
  32. </details>
  33. <script>
  34. (function () {
  35. var d = document.querySelector('.bx-install-lang');
  36. if (!d) return;
  37. document.addEventListener('click', function (e) {
  38. if (!d.contains(e.target))
  39. d.removeAttribute('open');
  40. });
  41. document.addEventListener('keydown', function (e) {
  42. if (e.key === 'Escape')
  43. d.removeAttribute('open');
  44. });
  45. })();
  46. </script>