Get plural form of the given singular form of a taxonomy name

I have multilingual blog (pl / en) which is currently built with Hugo 0.111.3. I would like to update to newest Hugo, but I’m struggling with making current structure working. The main issue was resolved, now I have problems with taxonomies - I currently have them translated like:

pl:
  taxonomies:
    category: kategorie
    tag: tagi
    series: serie

en:
  taxonomies:
    category: categories
    tag: tags
    series: series

Then, for rendering link to specific tag I use {{- $tagsTaxonomy := $.Site.Language.Params.Taxonomies.tag -}} and for displaying series information I use {{ range (.GetTerms site.Language.Params.Taxonomies.series) }}. This means I use taxonomies’ config key (tag, series) to fetch actual taxonomy name for current language, effectively having translated URLs and localised taxonomies in the front matter.

This approach does not work with latest Hugo, I get:

render of "page" failed: "/blog/layouts/_default/single.html:34:8": execute of template failed at <partial "series.html" (dict "cxt" . "page" $ "position" "top")>: error calling partial: "/blog/layouts/partials/series.html:3:20": execute of template failed at <site>: invalid value; expected string  render: failed to render pages: invalid value; expected string 

This is because site.Language.Params.Taxonomies.series is a string on 0.111.3 and is nil in the latest version. I believe this is related to this change. I see that in PaperMod theme I’m using they changed the way how they retrieve taxonomy terms to {{- $tags := .Language.Params.Taxonomies.tag | default "tags" }}, so I am wondering if I should define my taxonomies twice (once directly under language key, to define taxonomies, and once under languages.xx.params) to be able to get the localised terms and process the posts under taxonomies?

Alternative approach is to use i18n:

[taxonomy.category]
other = 'categories'

[taxonomy.tag]
other = 'tags'

[taxonomy.series]
other = 'series'

and then {{ range (.GetTerms (i18n "taxonomy.series")) }} and {{- $tagsTaxonomy := (i18n "taxonomy.tag") -}} but this does not look clean to me, as I would like to use taxonomies’ definition as a single source of truth.

Is there official recommendation how it should be done properly?

FYI, this works without i18n part (I mean: as on 0.111) when I do:

pl:
  taxonomies:
    category: kategorie
    tag: tagi
    series: serie
  params:
    taxonomies:
      category: kategorie
      tag: tagi
      series: serie

en:
  taxonomies:
    category: categories
    tag: tags
    series: series
  params:
    taxonomies:
      category: categories
      tag: tags
      series: series

and then e.g. {{ range (.GetTerms site.Params.Taxonomies.series) }}, BUT it does not work with:

pl:
  taxonomies: &taxonomies-pl
    category: kategorie
    tag: tagi
    series: serie
  params:
    <<: *taxonomies-pl

en:
  taxonomies: &taxonomies-en
    category: categories
    tag: tags
    series: series
  params:
    <<: *taxonomies-en

The former is error-prone as it require defining the same thing twice explicitly. I prefer the latter, which has only single source of truth and only re-uses dictionary with an YAML anchor, but it does not work as the dictionary is not populated into params. Seems like anchors are not supported?

We’re not reverting the new behavior. I think you were lucky that your approach worked in previous versions.

Use a partial to get the plural form of the given singular form of a taxonomy name.

layouts/partials/get-taxonomy-plural.html
{{/*
Returns the plural form of the given singular form of a taxonomy name.

@param {string} . The singular form of the taxonomy name.

@returns {string} The plural form of the taxonomy name.

@example {{ partial "get-taxonomy-plural.html" "tag" }}
*/}}

{{ $taxonomoySingular := . }}
{{ $taxonomyPlural := "" }}
{{ range site.Taxonomies }}
  {{ range . }}
    {{ if eq .Page.Data.Singular $taxonomoySingular }}
      {{ $taxonomyPlural = .Page.Data.Plural }}
      {{ break }}
    {{ end }}
  {{ end }}
  {{ if $taxonomyPlural }}
    {{ break }}
  {{ end }}
{{ end }}
{{ return $taxonomyPlural }}

layouts/_default/single.html
{{ $taxonomySingular := "tag" }}
{{ $taxonomyPlural := partial "get-taxonomy-plural.html" $taxonomySingular }}
{{ with .GetTerms $taxonomyPlural }}
  <p>{{ $taxonomyPlural }}:</p>
  <ul>
    {{ range . }}
      <li><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></li>
    {{ end }}
  </ul>
{{ end }}

This approach is fragile; I would use an i18n lookup instead.

I wasn’t expecting the revert, I just wanted to know if there’s an suggested approach :slightly_smiling_face:. When I implemented my blog structure I really studied docs and external content to find the approach that is in line with Hugo’s architecture and also with my personal requirements. It was working for long, at some point stopped, and I wanted to be up-to-date so had to find new solution. Thanks for the info, I’ll investigate options deeper when I have time, for now I’ll stick with duplicated taxonomies (without i18n).