diff --git a/content/en/content-management/multilingual.md b/content/en/content-management/multilingual.md index d1e7965b2..d384bd86b 100644 --- a/content/en/content-management/multilingual.md +++ b/content/en/content-management/multilingual.md @@ -507,6 +507,40 @@ The rendering of the main navigation works as usual. `.Site.Menus` will just con ``` +### Dynamically localizing menus with i18n +While customizing menus per language is useful, if you have a log of languages your config file can become hard to maintain. + +If your menus are the same in all languages, and the only thing that changes is the actual translation, you can use the menu `.Identifier` as a translation key for the name of the the menu: + +{{< code-toggle file="config" >}} +[[menu.main]] +name = "About me" +url = "about" +weight = 1 +identifier = "about" +{{< /code-toggle >}} + +You now need to specify the translations for the menu keys in the i18n files: + +{{< code file="i18n/pt.toml" >}} +[about] +other="Sobre mim" +{{< /code >}} + +And do the appropriate changes in the menu code to use the `i18n` tag with the `.Identifier` as a key. You will also note that here we are using a `default` to fall back to `.Name`, in case the `.Identifier` key is also not present in the language specified in the `defaultContentLanguage` configuration. + +{{< code file="layouts/partials/menu.html" >}} +