Repository: gohugoio/hugo (language: go)

Issue:
sectionPagesMenu config setting triggers warning on multilingual site for pages in root section
Reference: <https://discourse.gohugo.io/t/ananke-theme-warnings-about-duplicate-menu-entry-hugo-v0-124-1/49032>

> WARN  "/home/user/project/content/p1.en.md:1:1": duplicate menu entry with identifier "p1" in menu "main"
> WARN  "/home/user/project/content/p2.en.md:1:1": duplicate menu entry with identifier "p2" in menu "main"
> WARN  "/home/user/project/content/p1.fr.md:1:1": duplicate menu entry with identifier "p1" in menu "main"


These warnings began to appear with v0.123.0.

Minimal reproducible example:

```text
git clone --single-branch -b hugo-github-issue-12306 https://github.com/jmooring/hugo-testing hugo-github-issue-12306
cd hugo-github-issue-12306
hugo
```

If you remove `sectionPagesMenu = "main"` from the site config the warnings go away.

Here's a test case, but `AssertLogContains` isn't matching the log output from the minimal reproducible example above.

```go
func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['section','rss','sitemap','taxonomy','term']
defaultContentLanguageInSubdir = true
sectionPagesMenu = "main"
[languages.en]
[languages.fr]
-- layouts/_default/home.html --
{{- range site.Menus.main -}}
  <a href="{{ .URL }}">{{ .Name }}</a>
{{- end -}}
-- layouts/_default/single.html --
{{ .Title }}
-- content/p1.en.md --
---
title: p1
menu: main
---
-- content/p1.fr.md --
---
title: p1
menu: main
---
-- content/p2.en.md --
---
title: p2
menu: main
---
`

	b := hugolib.Test(t, files)

	b.AssertFileContent("public/en/index.html", `<a href="/en/p1/">p1</a><a href="/en/p2/">p2</a>`)
	b.AssertFileContent("public/fr/index.html", `<a href="/fr/p1/">p1</a>`)
	b.AssertLogNotContains("WARN") // I can't make this test work; container is ""
}
```




Discussion / hints:

Fix patch:
diff --git a/hugolib/site.go b/hugolib/site.go
index 6d2d6c85281..9ab361722c9 100644
--- a/hugolib/site.go
+++ b/hugolib/site.go
@@ -658,8 +658,13 @@ func (s *Site) assembleMenus() error {
 			if p.IsHome() || !p.m.shouldBeCheckedForMenuDefinitions() {
 				return false, nil
 			}
+
 			// The section pages menus are attached to the top level section.
 			id := p.Section()
+			if id == "" {
+				id = "/"
+			}
+
 			if _, ok := flat[twoD{sectionPagesMenu, id}]; ok {
 				return false, nil
 			}
@@ -671,6 +676,7 @@ func (s *Site) assembleMenus() error {
 				},
 				Page: p,
 			}
+
 			navigation.SetPageValues(&me, p)
 			flat[twoD{sectionPagesMenu, me.KeyName()}] = &me
 			return false, nil
@@ -678,6 +684,7 @@ func (s *Site) assembleMenus() error {
 			return err
 		}
 	}
+
 	// Add menu entries provided by pages
 	if err := s.pageMap.forEachPage(pagePredicates.ShouldListGlobal, func(p *pageState) (bool, error) {
 		for name, me := range p.pageMenus.menus() {


Test patch:
diff --git a/hugolib/menu_test.go b/hugolib/menu_test.go
index 8ff74304b0d..816ffb6763a 100644
--- a/hugolib/menu_test.go
+++ b/hugolib/menu_test.go
@@ -636,3 +636,43 @@ Menu Item: {{ $i }}|{{ .URL }}|
 Menu Item: 0|/foo/posts|
 `)
 }
+
+func TestSectionPagesMenuMultilingualWarningIssue12306(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- hugo.toml --
+disableKinds = ['section','rss','sitemap','taxonomy','term']
+defaultContentLanguageInSubdir = true
+sectionPagesMenu = "main"
+[languages.en]
+[languages.fr]
+-- layouts/_default/home.html --
+{{- range site.Menus.main -}}
+  <a href="{{ .URL }}">{{ .Name }}</a>
+{{- end -}}
+-- layouts/_default/single.html --
+{{ .Title }}
+-- content/p1.en.md --
+---
+title: p1
+menu: main
+---
+-- content/p1.fr.md --
+---
+title: p1
+menu: main
+---
+-- content/p2.en.md --
+---
+title: p2
+menu: main
+---
+`
+
+	b := Test(t, files, TestOptWarn())
+
+	b.AssertFileContent("public/en/index.html", `<a href="/en/p1/">p1</a><a href="/en/p2/">p2</a>`)
+	b.AssertFileContent("public/fr/index.html", `<a href="/fr/p1/">p1</a>`)
+	b.AssertLogNotContains("WARN")
+}