devcows / hugo-universal-theme

Universal theme for Hugo, it stands out with its clean design and elegant typography.
https://devcows.github.io/hugo-universal-theme
MIT License
788 stars 559 forks source link

add the option to translate menus' names using i18n #378

Open RichardAlmanza opened 1 year ago

RichardAlmanza commented 1 year ago

With this change, we can add in <root-project>/i18n/<desired-language>.yaml the respective menu translation

For example, let's use the exampleSite in this repo

in exampleSite/config.toml I'll use Spanish

defaultContentLanguage = "es"

then I create exampleSite/i18n/es.yaml file, with the following content

- id: menu.home
  translation: Inicio

- id: menu.features
  translation: Caracteristicas

- id: menu.portfolio
  translation: Portafolio

- id: section.about
  translation: Acerca de Nosotros

We only need the identifier property in the menu definition in the configuration, thus to translate more sub menus and items, we can add the property

in exampleSite/config.toml I'll add the property to packages

[[menu.main]]
    name       = "Packages"
    identifier = "item.packages" # new line
    url        = ""
    weight     = 1
    parent     = "section.marketing"

then I'll add the new translation in exampleSite/i18n/es.yaml

- id: item.packages
  translation: Paquetes

When there isn't a translation for an ID, it just keeps the name set in the configuration