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.
```toml
[languages.en]
weight = 1
title = "anemone"
languageName = "English"
languageCode = "en"
relativeURL = false
[languages.fr]
weight = 2
title = "anemone"
languageName = "Français"
languageCode = "fr"
relativeURL = false
taxonomies = [
{name = "tags", feed = true},
]
```
#### Multilanguage-Ready Navigation Bar
@ -78,21 +66,12 @@ Customize the header navigation links with the following code in the `extra` sec
```toml
[extra]
[[extra.header_nav]]
en = { name = "/home/", url = "/" }
fr = { name = "/accueil/", url = "/fr" }
[[extra.header_nav]]
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" }
header_nav = [
{ url = "/", name_en = "/home/", name_fr = "/accueil/" },
{ url = "/about", name_en = "/about/", name_fr = "/concernant/" },
{ url = "/journal", name_en = "/journal/", name_fr = "/journal/" },
{ url = "/blog", name_en = "/blog/", name_fr = "/blog/" }
]
```
#### Default Theme

View file

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

View file

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

View file

@ -92,4 +92,5 @@
{% block css %}
<link rel="stylesheet" href="{{ get_url(path='css/style.css', trailing_slash=false) | safe }}"/>
{% 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 %}
<nav class="navBar">
<nav class="navBar">
{% for nav_item in config.extra.header_nav %}
{% set current_nav_item = nav_item[lang] %}
{% if current_nav_item and current_nav_item.name %}
<a href="{{ get_url(path=current_nav_item.url) }}" {% if current_nav_item.new_tab %}target="_blank"
rel="noreferrer noopener" {% endif %}>{{ current_nav_item.name }}</a>
{% endif %}
<a href="{{ nav_item.url }}" class="{% if nav_item.url == current_url %}active{% endif %}">
{% set language_key = 'name_' ~ current_lang %}
{{ nav_item[language_key] }}
</a>
{% endfor %}
<div class="themeSwitch">