Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translationKey does not logically connect term pages #12261

Closed
jmooring opened this issue Mar 15, 2024 · 4 comments · Fixed by #12262
Closed

translationKey does not logically connect term pages #12261

jmooring opened this issue Mar 15, 2024 · 4 comments · Fixed by #12262

Comments

@jmooring
Copy link
Member

jmooring commented Mar 15, 2024

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.

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/|")
}
@jmooring
Copy link
Member Author

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.

@bep
Copy link
Member

bep commented Mar 15, 2024

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
---

@bep bep removed the NotSure label Mar 15, 2024
@bep bep modified the milestones: v0.125.0, v0.124.0 Mar 15, 2024
@bep
Copy link
Member

bep commented Mar 15, 2024

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)

@bep bep self-assigned this Mar 15, 2024
bep added a commit to bep/hugo that referenced this issue Mar 15, 2024
bep added a commit that referenced this issue Mar 15, 2024
Copy link

github-actions bot commented Apr 6, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants