Add basic support for multilingual site

Add language switcher on the top right of the site
Switches taxonomies, article paths, home, etc.
Every language is independent
This commit is contained in:
Teo-CD 2020-10-02 21:05:35 +02:00
parent 2d6b0f8173
commit e933a44125
2 changed files with 45 additions and 5 deletions

View file

@ -58,7 +58,11 @@
<div class="container"> <div class="container">
<div class="navbar-brand"> <div class="navbar-brand">
{% if config.extra.zulma_brand %} {% if config.extra.zulma_brand %}
{% if config.default_language is matching(lang) %}
<a class="navbar-item" href="/"> <a class="navbar-item" href="/">
{% else %}
<a class="navbar-item" href="{{"/" ~ lang ~ "/"}}">
{% endif %}
{% if config.extra.zulma_brand.image %} {% if config.extra.zulma_brand.image %}
<img src="{{ config.extra.zulma_brand.image | safe | replace(from="$BASE_URL", to=config.base_url) }}" <img src="{{ config.extra.zulma_brand.image | safe | replace(from="$BASE_URL", to=config.base_url) }}"
alt="{{ config.extra.zulma_brand.text }}"> alt="{{ config.extra.zulma_brand.text }}">
@ -77,11 +81,17 @@
<div class="navbar-end"> <div class="navbar-end">
{% if config.extra.zulma_menu %} {% if config.extra.zulma_menu %}
{% for item in config.extra.zulma_menu %} {% for item in config.extra.zulma_menu %}
{% set item_url = item.url | replace(from="$BASE_URL", to=config.base_url) %}
{% if config.default_language is matching(lang) %}
{% set item_url = item.url | replace(from="$BASE_URL", to=config.base_url) %}
{% else %}
{% set item_url = item.url | replace(from="$BASE_URL", to=config.base_url ~ "/" ~ lang) %}
{% endif %}
{% set item_url = item_url ~ "/" %} {% set item_url = item_url ~ "/" %}
<a itemprop="url" <a itemprop="url"
class="navbar-item {% if item_url == current_url %}is-active{% endif %}" class="navbar-item {% if item_url == current_url %}is-active{% endif %}"
href="{{ item.url | safe | replace(from="$BASE_URL", to=config.base_url) }}"> href="{{ item_url }}">
<span itemprop="name">{{ item.name }} <span itemprop="name">{{ item.name }}
</span> </span>
</a> </a>
@ -97,6 +107,36 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% if config.languages %}
{% if config.default_language is not matching(lang) %}
{% set lang_url = current_url | replace(from=config.base_url ~ "/" ~ lang, to=config.base_url) %}
<a itemprop="url"
class="navbar-item {% if lang_url == current_url %}is-active{% endif %}"
href="{{ lang_url }}">
<span itemprop="name">{{ config.default_language }}
</span>
</a>
{% endif %}
{% for available_lang in config.languages %}
{% set lang_code = available_lang.code %}
{% if lang_code is not matching(lang) %}
{% if lang is matching(config.default_language) %}
{% set lang_url = current_url | replace(from=config.base_url ~ "/", to=config.base_url ~ "/" ~ lang_code ~ "/") %}
{% else %}
{% set lang_url = current_url | replace(from=config.base_url ~ "/" ~ lang, to=config.base_url ~ "/" ~ lang_code) %}
{% endif %}
<a itemprop="url"
class="navbar-item {% if lang_url == current_url %}is-active{% endif %}"
href="{{ lang_url }}">
<span itemprop="name">{{ lang_code }}
</span>
</a>
{% endif %}
{% endfor %}
{% endif %}
</div> </div>
</div> </div>
</div> </div>

View file

@ -93,7 +93,7 @@
{% if page.taxonomies.authors %} {% if page.taxonomies.authors %}
by by
{% for author in page.taxonomies.authors %} {% for author in page.taxonomies.authors %}
<a href="{{ get_taxonomy_url(kind="authors", name=author) | safe }}"> <a href="{{ get_taxonomy_url(kind="authors", name=author, lang=page.lang) | safe }}">
<span class="tag is-primary">{{ author }} </span> <span class="tag is-primary">{{ author }} </span>
</a> </a>
{% if page.taxonomies.authors | length > 1 %} {% if page.taxonomies.authors | length > 1 %}
@ -113,7 +113,7 @@ and
{% macro post_footer_categories(page) %} {% macro post_footer_categories(page) %}
{% if page.taxonomies.categories %} {% if page.taxonomies.categories %}
{% set category = page.taxonomies.categories[0] %} {% set category = page.taxonomies.categories[0] %}
in <a href="{{ get_taxonomy_url(kind="categories", name=category) | safe }}"> in <a href="{{ get_taxonomy_url(kind="categories", name=category, lang=page.lang) | safe }}">
<span class="tag is-success"> <span class="tag is-success">
{{ category }} {{ category }}
</span> </span>
@ -126,7 +126,7 @@ in <a href="{{ get_taxonomy_url(kind="categories", name=category) | safe }}">
{% if page.taxonomies.tags %} {% if page.taxonomies.tags %}
and tagged and tagged
{% for tag in page.taxonomies.tags %} {% for tag in page.taxonomies.tags %}
<a href="{{ get_taxonomy_url(kind="tags", name=tag) | safe }}"> <a href="{{ get_taxonomy_url(kind="tags", name=tag, lang=page.lang) | safe }}">
<span class="tag is-link">{{ tag }} </span> <span class="tag is-link">{{ tag }} </span>
</a> </a>
{% if page.taxonomies.tags | length > 1 %} {% if page.taxonomies.tags | length > 1 %}