Repository: gohugoio/hugo (language: go)

Issue:
translationKey does not logically connect term pages
Reference: <https://discourse.gohugo.io/t/0-123-8-translationkey-does-not-connect-term-pages/48829>

This worked with v0.122.0, but does not work with v0.123.0 and later.

```go
func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['home','rss','section','sitemap','taxonomy']
defaultContentLanguage = 'en'
defaultContentLanguageInSubdir = true
[languages.en]
weight = 1
[languages.pt]
weight = 2
[taxonomies]
category = 'categories'
-- layouts/_default/list.html --
{{ .IsTranslated }}|{{ range .Translations }}{{ .RelPermalink }}|{{ end }}
-- layouts/_default/single.html --
{{ .Title }}|
-- content/p1.en.md --
---
title: p1 (en)
categories: [music]
---
-- content/p1.pt.md --
---
title: p1 (pt)
categories: [música]
---
-- content/categories/music/_index.en.md --
---
title: music
translationKey: foo
---
-- content/categories/música/_index.pt.md --
---
title: música
translationKey: foo
---
`

	b := hugolib.Test(t, files)
	b.AssertFileContent("public/en/categories/music/index.html", "true|/pt/categories/m%C3%BAsica/|")
	b.AssertFileContent("public/pt/categories/música/index.html", "true|/en/categories/music/|")
}
```



Discussion / hints:
There are two approaches to term translation:

1. Use the same term across all languages (e.g., "music"), then use different titles within the term branch bundle.
2. As shown in the example above, use language-specific terms and connect them via `translationKey` as needed.

I think the first is far more common, but I don't have any data to back that up.
The `translationKey` concept was a not so great idea, but I kept it to avoid breakage in the wild (but I obviously missed one spot). I have never seen this in use as in the example above, so this isn't a priority for me to fix. 

My current recommendation for all multilingual content in Hugo is to normalise the `Path` (e.g. to match the main content language). This way the above example would look like:

```
-- content/categories/music/_index.en.md --
---
title: music
---
-- content/categories/music/_index.pt.md --
---
title: música
---
```
Never mind, I had a quick look at the code and I don't see why it shouldn't work, so it should be an easy fix.

(but i would really recommend putting all the translations into the same folder, re. the above)

Fix patch:
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index 906fced77d4..64a15a59a33 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -1500,13 +1500,6 @@ func (sa *sitePagesAssembler) assembleTermsAndTranslations() error {
 				return false, nil
 			}
 
-			// This is a little out of place, but is conveniently put here.
-			// Check if translationKey is set by user.
-			// This is to support the manual way of setting the translationKey in front matter.
-			if ps.m.pageConfig.TranslationKey != "" {
-				sa.s.h.translationKeyPages.Append(ps.m.pageConfig.TranslationKey, ps)
-			}
-
 			if sa.pageMap.cfg.taxonomyTermDisabled {
 				return false, nil
 			}
@@ -1587,6 +1580,13 @@ func (sa *sitePagesAssembler) assembleResources() error {
 		Handle: func(s string, n contentNodeI, match doctree.DimensionFlag) (bool, error) {
 			ps := n.(*pageState)
 
+			// This is a little out of place, but is conveniently put here.
+			// Check if translationKey is set by user.
+			// This is to support the manual way of setting the translationKey in front matter.
+			if ps.m.pageConfig.TranslationKey != "" {
+				sa.s.h.translationKeyPages.Append(ps.m.pageConfig.TranslationKey, ps)
+			}
+
 			// Prepare resources for this page.
 			ps.shiftToOutputFormat(true, 0)
 			targetPaths := ps.targetPaths()


Test patch:
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index b0ab7f09c59..f22a4d07cd7 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -1350,6 +1350,51 @@ AllTranslations: {{ range .AllTranslations }}{{ .Language.Lang }}|{{ end }}|
 	)
 }
 
+func TestTranslationKeyTermPages(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['home','rss','section','sitemap','taxonomy']
+defaultContentLanguage = 'en'
+defaultContentLanguageInSubdir = true
+[languages.en]
+weight = 1
+[languages.pt]
+weight = 2
+[taxonomies]
+category = 'categories'
+-- layouts/_default/list.html --
+{{ .IsTranslated }}|{{ range .Translations }}{{ .RelPermalink }}|{{ end }}
+-- layouts/_default/single.html --
+{{ .Title }}|
+-- content/p1.en.md --
+---
+title: p1 (en)
+categories: [music]
+---
+-- content/p1.pt.md --
+---
+title: p1 (pt)
+categories: [música]
+---
+-- content/categories/music/_index.en.md --
+---
+title: music
+translationKey: foo
+---
+-- content/categories/música/_index.pt.md --
+---
+title: música
+translationKey: foo
+---
+`
+
+	b := Test(t, files)
+	b.AssertFileContent("public/en/categories/music/index.html", "true|/pt/categories/m%C3%BAsica/|")
+	b.AssertFileContent("public/pt/categories/música/index.html", "true|/en/categories/music/|")
+}
+
 // Issue #11540.
 func TestTranslationKeyResourceSharing(t *testing.T) {
 	files := `