language-selector.html.twig 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <ul class="language-selector">
  2. {% for language in language_selector.languages %}
  3. {% set show_language = true %}
  4. {% if language == language_selector.current %}
  5. {% set lang_url = page.url %}
  6. {% else %}
  7. {% set base_lang_url = base_url_simple ~ grav.language.getLanguageURLPrefix(language) %}
  8. {% set lang_url = base_lang_url ~ language_selector.page_route ~ page.urlExtension %}
  9. {% set untranslated_pages_behavior = grav.config.plugins.language_selector.untranslated_pages_behavior %}
  10. {% if untranslated_pages_behavior != 'none' %}
  11. {% set translated_page = language_selector.translated_pages[language] %}
  12. {% if (not translated_page) or (not translated_page.published) %}
  13. {% if untranslated_pages_behavior == 'redirect' %}
  14. {% set lang_url = base_lang_url ~ '/' %}
  15. {% elseif untranslated_pages_behavior == 'hide' %}
  16. {% set show_language = false %}
  17. {% endif %}
  18. {% endif %}
  19. {% endif %}
  20. {% endif %}
  21. {% if show_language %}
  22. <li>
  23. <a href="{{ lang_url ~ uri.params }}">
  24. {% if language_display.select == 'default' or language_display.select == 'name' %}
  25. {{ language|upper }}
  26. {% endif %}
  27. </a>
  28. </li>
  29. {% endif %}
  30. {% endfor %}
  31. </ul>