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:
/tags/terms.html
{{ 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!
Edit:
$ hugo env
Hugo Static Site Generator v0.74.3-DA0437B4/extended linux/amd64 BuildDate: 2020-07-23T16:30:30Z
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.14.3"
Besides the issue above, you have furthermore to consider some things that might be a problem for your readers:
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.
Regarding SEO this might be not optimal because users will search for Auto instead of car?
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?
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):
/random-post.md
tags:
- keys: ["car"]
- values: ["Auto"]
/terms.html
{{ range $.Site.Taxonomies.tags.keys }}
{{ .Params.tags.values }}
{{ end }}