langswitcher.html.twig 1.3 KB

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