Greetings,
Consider the two translations (English and Italian) of the same post, mytravels.md and mytravels.it.md, in a multilanguage Hugo website. They belong to the same category but of course that category has different names in each language: the frontmatter of mytravels.md will include “category: travels” and the frontmatter of mytravels.it.md will say “category: viaggi” (viaggi is the Italian translations of “travels”).
The sidebar of my theme lists categories and tags with this code:
{{ range $key, $value := .Site.Taxonomies }}
<header> <span>{{ $key | singularize | upper }}</span></header>
<div><ul>
{{ range first 7 $value.ByCount }}
<li><a href="{{ $.Site.BaseURL}}{{ $key }}/{{ .Name | urlize }}" class="list-group-item">{{ .Name }}</a></li>
{{ end }}
</ul>
</div>
as far as I’m concerned, this works fine on single language sites, not so on multilanguage ones. In the latter case, the code above is wrong in two ways:
- first, it lists italian categories in english pages and viceversa, while it should only list categories in the same language of the current page
- second, it lists them wrong, because it generates a link to example.com/category/viaggi/ (no language subfolder) while the rest of Hugo will (correctly) create example.com/it/category/viaggi/index.html and all the related pages (it/viaggi/page/2, 3, etc)
Is there a way to make the code above only list the categories and tags of the same language of the current page, and with the correct link? I already know that this is not possible for content folders, but is it doable with taxonomies only?
TIA,
M