Language specific category and tags links?


Consider the two translations (English and Italian) of the same post, and, 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 will include “category: travels” and the frontmatter of 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>
{{ range first 7 $value.ByCount }}
<li><a href="{{ $.Site.BaseURL}}{{ $key }}/{{ .Name | urlize }}" class="list-group-item">{{ .Name }}</a></li>
{{ end }}

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 (no language subfolder) while the rest of Hugo will (correctly) create 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?


I discovered only in this moment this other thread

that seems to be the solution. Am I right? I will test it asap, but that may be next week or later, so if anybody else wants to try it or comment, please do it!

Have a look at the rel/absLangURL template functions. They are aware of the current language and prepend the language code automatically in the url