How to create language independant menus

Hello,

I’m using hugo 0.31.1 and want to build a multilanguage site. As I also want to link a dynamic list of social pages/account, I thought I would define a menu for that but how do I create a menu that will be rendered the same regardless of the language used? For example the english main menu goes to [[languages.en.menu.main]] while the german one would go to *.de.* instead. This approach works very well but I don’t want to define the menu for each language as it will be the same.
I tried to use [[menu.social]] but when I access it via .Site.Menus.social, Hugo does not render anything as if the menu is not defined, although it gets detected because I can see it in the output when I type hugo config.
The documentation states that we can define language independent menus so maybe I’m just missing something?

Thanks for your help.

I struggled a bit with this also. Here’s a working example:

[Languages.en.menu]
[[Languages.en.menu.main]]
name = "About"
url = "/about/blog"
weight = 1
post = "This is more than meets the eye"

[[Languages.en.menu.main]]
name = "The Stories"
url = "/categories/"
weight = 2
post = "Come sit by the table, have a drink and read a tale"

[[Languages.en.menu.main]]
name = "The Author"
url = "/about/me/"
weight = 3
post = "Bruno Amaral"

[[Languages.en.menu.main]]
name = "Contact"
url = "/contact/"
weight = 4
post = "Don't be shy, reach out"

[Languages.pt]
weight = 2
LanguageName = "Portuguese"
subtitle = "Contos de uma mente hiperactiva"

[Languages.pt.menu]
[[Languages.pt.menu.main]]
name = "Sobre"
url = "/about/blog"
weight = 1
post = "Isto é mais do que um blog"

[[Languages.pt.menu.main]]
name = "As Histórias"
url = "/categories/"
weight = 2
post = "São mais do que estórias e menos do que histórias, mas contam mais do que contos."

[[Languages.pt.menu.main]]
name = "O Autor"
url = "/about/me/"
weight = 3
post = "Bruno Amaral"

[[Languages.pt.menu.main]]
name = "Contacto"
url = "/contact/"
weight = 4
post = "Diz qualquer coisa"
1 Like

Hello bruno,

thanks for the code. I already have a working menu which is different for each language. What I wanted was a menu which will be the same for each defined language but without having to define it multiple times. As far as it seems, this is not possible or I made some kind of mistake.

Ah sorry, I misunderstood what you were trying to do. Should have read more carefuly.

Another way to do this would be using a partial. is that an option ?

A partial would work but I wanted the menu to be dynamic so I can simply add another entry and it automatically reflects the change without duplicating the code (this also allows for easy ordering using weights). For now I have implemented it as menu for each language because it’s probably not quite good to have a multilanguage site but only one social page for all languages.