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