Share front matter between translations

Viewed 251

I have a Hugo site with translations per file, using page bundles.

So the About page looks like this:

- about
  - about-image.jpg
  - index.en.md
  - index.nl.md
  - index.fr.md

The problem is that I have to repeat the non-i18n front matter in all of the .md files.

For example, date, tags, et cetera.

Is there a way in hugo to define the (basic) front matter once, and have translations only contain overrides needed for i18n?

2 Answers

You can define the default language in the config file of the site. Then, you set the strings that do not need to be translated only into the translation file of the default language, and you do not define them in the other files.

As the translations are missing, Hugo will default to the default language (if defined in the config file). https://gohugo.io/content-management/multilingual/#missing-translations

Hugo now brings with it front-matter cascade param which you can use to make descendant pages or even translation pages like

cascade:
- _target:
    kind: page
    lang: en
    path: /blog/**
  background: yosemite.jpg
- _target:
    kind: section
  background: goldenbridge.jpg
title: Blog

Learn more here https://gohugo.io/content-management/front-matter#front-matter-cascade

Related