Possible bug for menu only defined in config file in multilingual site configuration

Hi,

I’ve got a problem with menus in my attempt to create a multilingual website.
I am using hugo version 0.26.

I configured my main menu in two languages inside the config.toml file like this:

baseURL = "http://www.example.com"
metaDataFormat = "yaml"
footnotereturnlinkcontents = "↩"
copyright = "Copyright © 2017"

defaultContentLanguage = "en"
defaultContentLanguageInSubdir = true

theme = "ysart"

# I18n
[Languages]

# English
[Languages.en]
title = "..."
weight = 1
languageName = "English"
languageCode = "en-us"
Author = "..."
Email = "..."
MediaDir = "/medias/"

[[languages.en.menu.main]]
name = "Games"
identifier = "games"
url = "/games/"
weight = 1

[[languages.en.menu.main]]
name = "Shorts"
identifier = "shorts"
url = "/shorts/"
weight = 2

[[languages.en.menu.main]]
name = "Lab"
identifier = "lab"
url = "/lab/"
weight = 3

[[languages.en.menu.main]]
name = "Illustrations"
identifier = "illustrations"
url = "/illustrations/"
weight = 4

[[languages.en.menu.main]]
name = "Scripts"
identifier = "scripts"
url = "/scripts/"
weight = 5

[[languages.en.menu.main]]
name = "Store"
identifier = "store"
url = "/store/"
weight = 6

[[languages.en.menu.main]]
name = "Contact"
identifier = "contact"
url = "/contact/"
weight = 7


# French
[Languages.fr]
title = "..."
weight = 2
languageName = "Français"
languageCode = "fr"
Author = "..."
Email = "..."
MediaDir = "/medias/"

[[languages.fr.menu.main]]
name = "Jeux Vidéo"
identifier = "games"
url = "/games/"
weight = 1

[[languages.fr.menu.main]]
name = "Court Métrages"
identifier = "shorts"
url = "/shorts/"
weight = 2

[[languages.fr.menu.main]]
name = "Lab"
identifier = "lab"
url = "/lab/"
weight = 3

[[languages.fr.menu.main]]
name = "Illustrations"
identifier = "illustrations"
url = "/illustrations/"
weight = 4

[[languages.fr.menu.main]]
name = "Scripts"
identifier = "scripts"
url = "/scripts/"
weight = 5

[[languages.fr.menu.main]]
name = "Boutique"
identifier = "store"
url = "/store/"
weight = 6

[[languages.fr.menu.main]]
name = "Contact"
identifier = "contact"
url = "/contact/"
weight = 7

but the return of template debugging for the menu is nil if I do not add sectionPagesMenu = "main" in the config file.
But doing so, will add menu items i do not want.

Here is the menu template I am using and taken from the docs:

<ul>
    {{- $currentPage := . -}}
    {{ range .Site.Menus.main -}}
    <li class="{{ if $currentPage.IsMenuCurrent "main" . }}active{{ end }}">
        <a href="{{ .URL | absLangURL }}">{{ .Name }}</a>
    </li>
    {{- end }}
</ul>

I just want to define the menu in the config file and not in the front-matter.
Why do i have an empty menu without the sectionPagesMenu setting ? Did i do something wrong with my configuration ?

I have also verified that my partial calls do not miss the dot for passing the context variables.

NB: I also noticed that the menu items’ weight are not taken into account if i add sectionPagesMenu = "main" setting.

Thanks in advance for any help.

1 Like

EDIT: After a few tests, this may be a possible bug. I am opening and issue.
You can find more details about it there if you’re interested: https://github.com/gohugoio/hugo/issues/3819

1 Like

Hi Yann. The above issue refers back to this very forum post but there aren’t any new replies here. I might have stumbled upon the same issue. Did you find a solution?

I’m having the same issue. My menu system was working fine prior to attempting to add multi-lingual. When I add these settings, the menu disappears.

[Languages]
[Languages.en]
weight = 0
languageName = "English"

[[languages.en.menu.main]]
  name = "events"
  url = "/events"
  weight = -150
[[languages.en.menu.main]]
  name = "blog"
  url = "/blog"
  weight = -140
[[languages.en.menu.main]]
  name = "sponsor"
  url = "/sponsor"
  weight = -130
[[languages.en.menu.main]]
  name = "speaking"
  url = "/speaking"
  weight = -120
[[languages.en.menu.main]]
  name = "organizing"
  url = "/organizing"
  weight = -110
[[languages.en.menu.main]]
  name = "about"
  url = "/about"
  weight = -100

does not work, but:

[[menu.main]]
  name = "events"
  url = "/events"
  weight = -150
[[menu.main]]
  name = "blog"
  url = "/blog"
  weight = -140
[[menu.main]]
  name = "sponsor"
  url = "/sponsor"
  weight = -130
[[menu.main]]
  name = "speaking"
  url = "/speaking"
  weight = -120
[[menu.main]]
  name = "organizing"
  url = "/organizing"
  weight = -110
[[menu.main]]
  name = "about"
  url = "/about"
  weight = -100

does :confused:

EDIT: I found that when I made the menus the very last part of my config file, they now worked.

I’ve seen this issue before, and it has to do with the config format (TOML in this case). I haven’t run into this specific issue, and I can’t find the discussion, but it had to do with the way arrays are defined, and when folks put their thing at the end it always works.

Hope that helps folks figure that particular thing out. :face_with_raised_eyebrow:

Same issue here.

I did not investigate properly—but it makes a difference differenciating between Languages and languages, Languages.en and languages.en, Languages.en.menu.main and languages.en.menu.main (upper versus lower case).

Could not get a multilingual menu working, yet.

I had similar problems defining multi-language menus.

There is (seems to be) a kind of path logic when looking for variables. While for templates, this logic is pretty well explained, for variables, it is not, (or at least I have not found it.) This is in my opinion the most important thing missing in an otherwise very well made documentation :grinning:

I solved the problem by defining a partial template with a half-hard-coded menu structure integrating i18n for the labelling of the menus. :sunglasses:

This was super hard (for me) to find but, I ran into this problem where, the menus I’d specified in config.toml simply would not render. What fixed it, was to make the word “language” consistently lowercase.

This does not work:

[Languages]
[Languages.en]
weight = 0
languageName = "English"

[[languages.en.menu.main]]
  name = "Blog"
  url = "/posts"
  weight = 10

... etc

This does:

[languages]
[languages.en]
weight = 0
languageName = "English"

[[languages.en.menu.main]]
  name = "Blog"
  url = "/posts"
  weight = 10

...etc

I speculate, that Hugo considers “Languages” and “languages” different structures.

Also, I tried it, but, moving the menus to the end of the file made no difference in my test.

cc @bep

1 Like

When defining multilingual menus the IsMenuCurrent function does not work as expected.

The code taken straight from the docs can confirm this bug; https://gohugo.io/content-management/multilingual/#menus

See my comment on the issue on github;