DEV Community

Julien Maury
Julien Maury

Posted on • Updated on • Originally published at

Handle Hugo translations

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"
Enter fullscreen mode Exit fullscreen mode

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 }}
Enter fullscreen mode Exit fullscreen mode


Discussion (0)