-
Huste, Tobias authored
This does not implement multilanguage support for the whole website, but only for the content of specific pages.
Huste, Tobias authoredThis does not implement multilanguage support for the whole website, but only for the content of specific pages.
language-selector.html 1.03 KiB
{%- assign posts=site.posts | where:"lang_ref", page.lang_ref | where_exp: "post", "page.lang != post.lang" | sort: 'path' -%}
{%- assign pages=site.pages | where:"lang_ref", page.lang_ref | where_exp: "item", "page.lang != item.lang" | sort: 'path' -%}
{%- if posts.size > 0 -%}
{% assign items = posts %}
{%- else -%}
{% assign items = pages %}
{%- endif -%}
{%- comment -%}
Only grab elements from the post list, that are the equivalent according to
the lang_ref metadata. Also ensure, that only posts are grabbed that have a
different language.
{%- endcomment -%}
{%- assign t = site.data._i18n.translations[page.lang]['global'] -%}
<p class="text-right">
{%- for item in items -%}
{%- assign language_text = "lang-" | append: item.lang -%}
{%- if forloop.first -%}
<i class="fas fa-globe-europe"></i> <i>{{ t['lang-selector'] }} </i>
{%- endif -%}
<a href="{{ item.url | relative_url }}">{{ t[language_text] }}</a>
{%- unless forloop.last -%}
|
{%- endunless -%}
{%- endfor -%}
</p>