Internationalize Taxonomy Terms


I’m trying to internationalize my taxonomies (let’s say tags).

I chose to only use english keys for my tags (posts written in english and other languages) and to provide appropriate translations of every keys in my translation files in the /i18n directory.

This works pretty well except with the taxonomy terms.

So I have a partial like this:


{{ range $.Site.Taxonomies.tags }}
    {{ i18n .Page.Title }} 
{{ end }}

Problem: .Page.Title doesn’t get translated by the i18n function.

I also tried some variants like {{ i18n (.Page.Title) }} and {{ .Page.Title | i18n }}.

Why is the i18n function failing to translate my tag?
Am I missing something?
Have anyone found a solution for this?

Thanks for you help!


$ hugo env
Hugo Static Site Generator v0.74.3-DA0437B4/extended linux/amd64 BuildDate: 2020-07-23T16:30:30Z

For testing purposes you can use the following snippet, so you can see the following:

  • is there any output? (correct partial inclusion?)
  • what are the correct keys? (check spelling and uppercases etc.)
{{ range $.Site.Taxonomies.tags }}
    {{ i18n .Page.Title }} {{ .Page.Title }}<br>
{{ end }}

Are you sure you have added the tags as keys in the language files?

In my case everyting works as expected with the same hugo version, so I think the problem is on your site and not caused by the i18n function.

Besides the issue above, you have furthermore to consider some things that might be a problem for your readers:

  1. If you only translate your tags, the key will be the same for all language versions, so the URL will have the same key. For example: tag = car and in the German version the readers will read Auto but in the URL there is still car.
  2. Regarding SEO this might be not optimal because users will search for Auto instead of car?
  3. For each new tag you have to update your language files as well. Maybe it’s easier to provide them simply within the post’s front matter?

But of course, this is all up to you :slight_smile:

Hi @Lednerb!

Thanks a lot for your detailed answer.

I managed to get this working with the following code:

{{ range $.Site.Taxonomies.tags }}
    {{ i18n .Term }}
{{ end }}

Somehow .Page.Title was not being translated by i18n while .Terms was, all things equal…

You’re fundamentally right, this set up isn’t optimal…
Yet it allows me to automate connections between taxonomies (tags, categories) by simply toggling language code in URL.

I’m OK with having my slugs written in English for all languages and I don’t really care about SEO.
Nevertheless, I would be happy with an alternative approach that would still preserves the convenient reconciliation of terms between languages.

With the same logic, I believe I could go a step further and ditch the language files update by using nested front params but I don’t really know how I could proceed yet.
Maybe something like this (untested):


 - keys: ["car"]
 - values: ["Auto"]


{{ range $.Site.Taxonomies.tags.keys }}
    {{ .Params.tags.values }}
{{ end }}

Ok to close this I ended up using this solution in the taxonomy and terms layout templates:

{{ i18n (.Title) (len .Data.Pages) | humanize }}

This means I’m now using the same english keywords for pages written in all languages and setting the appropriate translations in my i18n files.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.