DEV Community

loading...

Handle Hugo translations

jmau111 profile image Julien Maury Originally published at blog.julien-maury.dev Updated on ・1 min read

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

Awesome!

Discussion (1)

pic
Editor guide
Collapse
jmau111 profile image
Julien Maury Author

the documentation link is gohugo.io/content-management/multi..., it's called "Bypassing default linking"