language-selector.html.twig 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <div class="language-selector">
  2. <button class="btn" type="button" data-dropdown="langSelectorList">
  3. {% if language_display.button == 'default' or language_display.button == 'flag' %}
  4. <img alt="{{ native_name(language_selector.current)|capitalize }}" src="{{ path_flags ~ language_selector.current }}.png" />
  5. {% endif %}
  6. {% if language_display.button == 'default' or language_display.button == 'name' %}
  7. {{ native_name(language_selector.current)|capitalize }}
  8. {% endif %}
  9. <i class="fa fa-caret-down"></i>
  10. </button>
  11. <ul class="dropdown-menu" id="langSelectorList">
  12. {% for language in language_selector.languages %}
  13. {% set show_language = true %}
  14. {% if language == language_selector.current %}
  15. {% set lang_url = page.url %}
  16. {% else %}
  17. {% set base_lang_url = base_url_simple ~ grav.language.getLanguageURLPrefix(language) %}
  18. {% set lang_url = base_lang_url ~ language_selector.page_route ~ page.urlExtension %}
  19. {% set untranslated_pages_behavior = grav.config.plugins.language_selector.untranslated_pages_behavior %}
  20. {% if untranslated_pages_behavior != 'none' %}
  21. {% set translated_page = language_selector.translated_pages[language] %}
  22. {% if (not translated_page) or (not translated_page.published) %}
  23. {% if untranslated_pages_behavior == 'redirect' %}
  24. {% set lang_url = base_lang_url ~ '/' %}
  25. {% elseif untranslated_pages_behavior == 'hide' %}
  26. {% set show_language = false %}
  27. {% endif %}
  28. {% endif %}
  29. {% endif %}
  30. {% endif %}
  31. {% if show_language %}
  32. <li>
  33. <a href="{{ lang_url ~ uri.params }}">
  34. {% if language_display.select == 'default' or language_display.select == 'flag' %}
  35. <img alt="{{ native_name(language)|capitalize }}" src="{{ path_flags ~ language }}.png" />
  36. {% endif %}
  37. {% if language_display.select == 'default' or language_display.select == 'name' %}
  38. {{ native_name(language)|capitalize }}
  39. {% endif %}
  40. </a>
  41. </li>
  42. {% endif %}
  43. {% endfor %}
  44. </ul>
  45. </div>