Multilingual Tags - bypass default linking

The word “kurztipp” translated into English is “quick-tip”. On German web pages, I use “kurztipp” as the tag name and “quick-tip” on the translated pages. How can I create a connection between the tags? If I display the tag list “quick-tip” and change the language to German the German blog posts should be displayed with the tag “kurztipp” and vice versa. If the tag name is identical in German and English it works.

Under themes/mytheme/layouts/taxonomy/tag I created two Front Matter Markdown files with an identical translationKey:

kurztipp.md

title: “kurztipp”
translationKey: “quicktip”

quick-tip.en.md

title: “quick-tip”
translationKey: “quicktip”

But it does not work. What am I doing wrong?

Structure

content/
├── de/
│   ├── posts/
│   │   └── post-1.md
│   ├── tags/
│   │   └── kurztipp/
│   │       └── _index.md  <-- translationKey = 'kurztipp'
│   └── _index.md
└── en/
    ├── posts/
    │   └── post-1.md
    ├── tags/
    │   └── quick-tip/
    │       └── _index.md  <-- translationKey = 'kurztipp'
    └── _index.md

Example

git clone --single-branch -b hugo-forum-topic-42516 https://github.com/jmooring/hugo-testing hugo-forum-topic-42516
cd hugo-forum-topic-42516
hugo server
1 Like

Thank you. My structure is as follows:

content/blog/adjust-date
content/blog/adjust-date/img/picture1.jpg
content/blog/adjust-date/index.en.md
content/blog/adjust-date/index.md
content/blog/pagination/img/picture1.jpg
content/blog/pagination/index.en.md
content/blog/pagination/index.md
content/blog/_index.en.md
content/blog/_index.md

The following does not work:

content/blog/adjust-date/
content/blog/tags/
content/blog/tags/kurztipp/_index.md
content/blog/tags/quick-tip/_index.md
content/blog/_index.en.md
content/blog/_index.md

Did you clone and test the example that I provided?

Yes, I have. I have a different structure. That’s why I don’t understand the example.

There’s no way that’s going to work. It would have to be:

content/tags/kurztipp/_index.md
content/tags/quick-tip/_index.md

This also does not work. Unfortunately.

Guessing is an inefficient usage of our time. Perhaps you can share your repository, privately if you wish.

Yes, I will send you a private email tomorrow. Thank you.

You do not separate your translations by directory, but instead use this structure:

content/posts/
├── post-1.en.md
└── post-1.md

Which is fine; we just need to use a different approach to translate and link the tags.

Please pull this again and test:

git clone --single-branch -b hugo-forum-topic-42516 https://github.com/jmooring/hugo-testing hugo-forum-topic-42516
cd hugo-forum-topic-42516
hugo server

With this approach you use the same tag for all languages, but control its appearance (name) and URL in the term’s front matter.

You will need to modify your tag cloud code accordingly, something like:

<div class="widget">
  <div class="tag-cloud-tags widget-content">
    {{- $taxonomy := "tags" -}}
    {{- range $term, $weightedPages := index site.Taxonomies $taxonomy -}}
      {{- $t := site.GetPage (printf "/%s/%s" $taxonomy $term) -}}
      {{- $currentFontSize := (add $smallestFontSize (mul (sub $weightedPages.Count $minCount) $sizeStep)) -}}
        <a href="{{ $t.RelPermalink }}" aria-label="{{ $t.Title }} ({{ $weightedPages.Count }} posts)" class="tag-link" style="font-size:{{- $currentFontSize -}}rem; color:{{- partial "shuffelColor.html" . -}}; transform:rotate({{- partial "shuffelRotate.html" . -}});">{{- $t.Title -}}
          <span style="font-size: {{- $smallestFontSize -}}rem"> ({{- $weightedPages.Count -}})</span></a>
    {{- end -}}
  </div>
</div>

Do I understand this correctly now? For a multilingual website I have to create directories for the different languages in the content directory - de, en. Then I copy my current Page Bundles into both directories. Delete index.en.md in the “de” directory and index.md in the “en” directory and index.en.md is renamed to index.md. I have to change the config.toml accordingly.

I still come from a time when memory was valuable. That’s why I liked the Page Bundles approach - store images only once, for one blog post all in one place and not scattered in different directories. My blog posts are all about Hugo and web design. It makes no sense to translate English IT terms into German, then no one understands you anymore. “Kurztipp” = “Quick-tip” is therefore the only tag which is different from the language. It’s amazing that the whole thing worked at all until now.

No.

Please clone the revised example and look at the structure. Or I can post your revised site to a repository somewhere.

EDIT: I did not push the changes earlier today. I just pushed them. Please clone and test.

As I understand it, we need to create an _index.md file with that translationKey in frontmatter for each of our tags, right? Guess there’s no way to automate it :thinking:

There are two methods to organize multilingual site content. Whether or not you need a translation key depends on which method you choose. And this discussion is limited to taxonomy term translations, including the URL.

Thanks, Joe. In my case I’m using different folders for each of my languages. Didn’t know about that bypassing though, so I was keeping always the same structure.

Thanks a lot Joe. Your advice on displaying the tags instead of {{ with .Params.tags }} {{ range . }} to output the tags with {{ range .GetTerms “tags” }} was key in addition to the hints above. Now “kurztipp” is also translated correctly.

1 Like

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