Handle Hugo translations

01/03/2021
1 min read
Disponible aussi en Fran├žais

I’ve played again with Hugo these days, and I fell in love with the built-in multilingual system.

Hugo has such a smart approach, and I can easily combine the i18n built-in tools with my markdown files.

Their documentation is fantastic, but I did not easily find a specific element, which is excellent, and you might need it.

Instead of using the symlink approach, you are free to use a special tag in your markdown frontmatter: translationKey:

translationKey = "hugo-i18n"

Use it in all translation .md files, including the parent (in the default language), and that’s it!

You only have to wrap with the following condition in your templates to display the translation links:

{{- if .IsTranslated }} 
  {{- range .Translations }}
    <a href="{{ .Permalink }}">{{ .Title }}</a>
  {{- end }}
{{- end }}

Awesome!

See Also