Menu definition in hugo.toml for a multinational site

Following the Hugo docs on Multilingual mode > Menus > Use translation tables, I have created the menu structure for a multinational site in hugo.toml and translated each identifier in i18n files. I have put a minimal example at GitHub - hcszt/minimal-menu

I expected that the menu entries get translated and point to the corresponding translated pages.

However, even though the translation of the identifiers work, each menu item points to the language with the highest weight rather than the language indicated by the translation.

Is there a simpler way to fix the links to the correct language rather than copying the menu definition –unchanged– in individual menus.<languageCode>.toml?

I am the person who reworked the menu content a few months ago. I went back to the test site I used during this process, and found that I had been using a multilingual, multihost setup. So, the documentation is incorrect.

I need to either (a) come up with a menu template for multilingual, single host setup where the menu entries in site configuration are not separated by language, or (b) rewrite a portion of the documentation.

In the interim, separate menu entries by language.

Sorry about the hassle.

1 Like

This config works for:

  • Monolingual sites
  • Multilingual sites
  • Multilingual multihost sites
└── _default/
    β”œβ”€β”€ menus/
    β”‚   β”œβ”€β”€
    β”‚   └── menu.en.toml
    └── hugo.toml

If the items in each menu are identical, just copy the entire file to the other language. I have updated the documentation:

1 Like

Thank you for the clarification. It looked to good to be true… :smile:

How could I approach this: loop through the translations of each menu entry (if I find these :thinking:) and pick the correct one…? I myself would not mind some complexity here if I could get rid of some files for it.

It’s possible, but in my view not worth the effort.

Getting the page itself isn’t too bad. You already have a page reference for the primary site, so query .AllTranslations for the page with .Language.Lang equal to the current page’s .Language.Lang.

In the non-primary languages (sites), the .IsMenuCurrent and .HasMenuCurrent methods will fail, so you’ll need to come up with alternatives, probably using the .Eq and .Ancestors methods.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.