Translate tags / taxonomies?


#1

I am trying to translate tags in Hugo.

My tags are only declared in the metadata of my posts:

---
author: arthur.sw
date: 2007-01-01T00:00:35Z
tags:
  - experiment
  - reflection
---

... post content ...

I translated them in my language files:

/i18n/en.toml:

[Experiment]
one = "Experiment"
other = "Experiments"

[Reflection]
one = "Reflection"
other = "Reflections"

/i18n/fr.toml:

[Experiment]
one = "Expérience"
other = "Expériences"

[Reflection]
one = "Réflexion"
other = "Réflexions"

But it never translates the tags, no matter if I use capital letters or not.

I also tried to modify my layouts/_default/list.html:

[...]

        <h1 class='title'>
          {{- if eq .Kind "taxonomy" -}}
          <span class='taxonomy-type'>
            {{- ( ( i18n .Data.Singular 1 ) | default .Data.Singular ) | title -}}
            {{- print ": " -}}
          </span>
          {{- end -}}

          {{- i18n .Title -}}
            
        </h1>

[...]

(I added i18n before .Title to translate the taxonomy name) But this does not work either.

How can I translate tags?

Here is the corresponding stackoverflow question.


#2

Similar question here. How to deal with i18n and taxonomies?

I was hoping to be able to use the _index.md files for taxonomies:

With a taxonomy categories, I have the value cs

I create <content>/categories/cs/_index.md, with:

title: "Computer Science"

I create content/categories/cs/_index.fr.md, with:

title: "Informatique Fondamentale"

Then on for a page summary, I would list its categories and display their title:

{{ range .Params.categories }}
  {{ .Title }}
{{ end }}

This doesn’t work now because {{ . }} is just the string name of the category.


#3

Correct.

You will need to get the category page with .GetPage

{{ .Site.GetPage "taxonomy" "categories" "cs" }}

In your context:

{{ range .Params.categories }}
  {{ $.Site.GetPage "taxonomy" "categories" .).Title }}
{{ end }}

#4

Hi, same question here.
Is there some documentation somewhere about how to deal with taxonomies and i18n ?