streamlined how multilingual support works

This commit is contained in:
Speyll 2023-11-08 00:19:50 +01:00
parent ccbee0ef42
commit ed97e270b8
5 changed files with 42 additions and 81 deletions

View file

@ -53,23 +53,11 @@ list_pages = true
The theme has a built-in feature that allows you to use multiple languages. For detailed instructions on how to use this feature, you can refer to the [Zola Multilingual documentation](https://www.getzola.org/documentation/content/multilingual/). This documentation provides additional information on how to make the most out of this multilingual capability. The theme has a built-in feature that allows you to use multiple languages. For detailed instructions on how to use this feature, you can refer to the [Zola Multilingual documentation](https://www.getzola.org/documentation/content/multilingual/). This documentation provides additional information on how to make the most out of this multilingual capability.
```toml ```toml
[languages.en]
weight = 1
title = "anemone"
languageName = "English"
languageCode = "en"
relativeURL = false
[languages.fr] [languages.fr]
weight = 2 weight = 2
title = "anemone" title = "anemone"
languageName = "Français" languageName = "Français"
languageCode = "fr" languageCode = "fr"
relativeURL = false
taxonomies = [
{name = "tags", feed = true},
]
``` ```
#### Multilanguage-Ready Navigation Bar #### Multilanguage-Ready Navigation Bar
@ -78,21 +66,12 @@ Customize the header navigation links with the following code in the `extra` sec
```toml ```toml
[extra] [extra]
[[extra.header_nav]] header_nav = [
en = { name = "/home/", url = "/" } { url = "/", name_en = "/home/", name_fr = "/accueil/" },
fr = { name = "/accueil/", url = "/fr" } { url = "/about", name_en = "/about/", name_fr = "/concernant/" },
{ url = "/journal", name_en = "/journal/", name_fr = "/journal/" },
[[extra.header_nav]] { url = "/blog", name_en = "/blog/", name_fr = "/blog/" }
en = { name = "/about/", url = "/about" } ]
fr = { name = "/concernant/", url = "/about" }
[[extra.header_nav]]
en = { name = "/journal/", url = "/journal" }
fr = { name = "/journal/", url = "/journal" }
[[extra.header_nav]]
en = { name = "/blog/", url = "/blog" }
fr = { name = "/blog/", url = "/blog" }
``` ```
#### Default Theme #### Default Theme

View file

@ -3,30 +3,16 @@ description = "A minimalist Zola theme that prioritizes clean CSS and avoids hea
compile_sass = false compile_sass = false
minify_html = true minify_html = true
generate_feed = true generate_feed = true
default_language = "en" default_language = "en"
taxonomies = [ taxonomies = [
{name = "tags", feed = true}, {name = "tags", feed = true},
] ]
[languages.en]
weight = 1
title = "anemone"
languageName = "English"
languageCode = "en"
relativeURL = false
[languages.fr] [languages.fr]
weight = 2 weight = 2
title = "anemone"
languageName = "Français" languageName = "Français"
languageCode = "fr" languageCode = "fr"
relativeURL = false
taxonomies = [
{name = "tags", feed = true},
]
[markdown] [markdown]
render_emoji = true render_emoji = true
@ -54,18 +40,9 @@ default_theme = "light"
list_pages = false list_pages = false
twitter_card = true twitter_card = true
[[extra.header_nav]] header_nav = [
en = { name = "/home/", url = "/" } { url = "/", name_en = "/home/", name_fr = "/accueil/" },
fr = { name = "/accueil/", url = "/fr" } { url = "/about", name_en = "/about/", name_fr = "/concernant/" },
{ url = "/journal", name_en = "/journal/", name_fr = "/journal/" },
[[extra.header_nav]] { url = "/blog", name_en = "/blog/", name_fr = "/blog/" }
en = { name = "/about/", url = "/about" } ]
fr = { name = "/concernant/", url = "/about" }
[[extra.header_nav]]
en = { name = "/journal/", url = "/journal" }
fr = { name = "/journal/", url = "/journal" }
[[extra.header_nav]]
en = { name = "/blog/", url = "/blog" }
fr = { name = "/blog/", url = "/blog" }

View file

@ -1,19 +1,18 @@
<!doctype html> <!DOCTYPE html>
<html lang="{{ lang }}"> <html lang="{% if page %}{{ page.lang }}{% else %}{{ config.default_language }}{% endif %}">
<head> <head>
{% include "head.html" %} {% include "head.html" %}
</head> </head>
<body> <body>
<div class="wrapper">
<header> <header>
{% include "header.html" %} {% include "header.html" %}
</header> </header>
<main> <main>
{% block content %}{% endblock content %} {% block content %}
{% endblock content %}
</main> </main>
<footer> <footer>
{% include "footer.html" %} {% include "footer.html" %}
</footer> </footer>
</div> </body>
</body>
</html> </html>

View file

@ -92,4 +92,5 @@
{% block css %} {% block css %}
<link rel="stylesheet" href="{{ get_url(path='css/style.css', trailing_slash=false) | safe }}"/> <link rel="stylesheet" href="{{ get_url(path='css/style.css', trailing_slash=false) | safe }}"/>
{% endblock css %} {% endblock css %}
<script src="{{ get_url(path='js/script.js', trailing_slash=false) | safe }}"></script> <script src="{{ get_url(path='js/script.js', trailing_slash=false) | safe }}" defer></script>

View file

@ -1,11 +1,16 @@
{% set current_lang = config.default_language %}
{% if page %}
{% set current_lang = page.lang %}
{% elif section %}
{% set current_lang = section.lang %}
{% endif %}
{% if config.extra.header_nav %} {% if config.extra.header_nav %}
<nav class="navBar"> <nav class="navBar">
{% for nav_item in config.extra.header_nav %} {% for nav_item in config.extra.header_nav %}
{% set current_nav_item = nav_item[lang] %} <a href="{{ nav_item.url }}" class="{% if nav_item.url == current_url %}active{% endif %}">
{% if current_nav_item and current_nav_item.name %} {% set language_key = 'name_' ~ current_lang %}
<a href="{{ get_url(path=current_nav_item.url) }}" {% if current_nav_item.new_tab %}target="_blank" {{ nav_item[language_key] }}
rel="noreferrer noopener" {% endif %}>{{ current_nav_item.name }}</a> </a>
{% endif %}
{% endfor %} {% endfor %}
<div class="themeSwitch"> <div class="themeSwitch">