Hi, I currently have an [extra] section that looks like this:
[extra]
nav = [
{ name = "Tjenester", path = "/tjenester" },
{ name = "Kontakt", path = "/kontakt" },
{ name = "Om oss", path = "/om" },
]
footer = [
{ name = "Våre klienter", path = "/klienter" },
{ name = "Bli medlem", path = "/bli-medlem" },
{ name = "Nyheter", path = "/nyheter" },
]
This is in Norwegian, which is the default language of the site. I am currently translating the site to English, and have been trying to be able to translate the nav and footer so that “Tjenester” becomes “Services”, etc.
How should I go about doing this? The documentation on multilingual sites doesn’t seem to cover this.
I can share our PR if this is not enough information.
Thanks!
Hi, I got a workaround.
In config.toml, add lang tag to key attribute like below
[extra.en]
nav = "...."
[extra.zh]
nav = "...."
In template file, try this
<nav>
{% set nav = config.extra[lang].nav %}
...
</nav>
Note that the lang
variable is predefined by zola. See Overview | Zola
I have a different approach, which is to just put in the slug, and use the template to get the section title in the current language.
I have code to show all the sections off the main index page of the site:
{% for s in index.subsections %}
{% set subsection = get_section(path=s) %}
{% if subsection.pages %}
<h3>{{ subsection.title }}</h3>
<ul class="list-unstyled">
{% for page in subsection.pages %}
<li><a class="docs-link{% if current_url == page.permalink %} active{% endif %}" href="{{ page.permalink | safe }}">{{ page.title }}</a></li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
This just gets the sections directly, without them being hard coded. However, if what you have just loop through using your path to get the current language:
{% for current_section in config.extra.nav %}
{% nav_item = get_section(path=current_section.path) %}
{{ nav_item.title | safe }}
{% end_nav %}
{% endfor %}
You can make it so nav is just an array of paths, and not having the names at all.