Translations
Syntax
PAGE.Translations
Returns
page.Pages
With this site configuration:
hugo.
defaultContentLanguage: en
languages:
de:
contentDir: content/de
languageCode: de-DE
languageName: Deutsch
weight: 2
en:
contentDir: content/en
languageCode: en-US
languageName: English
weight: 1
fr:
contentDir: content/fr
languageCode: fr-FR
languageName: Français
weight: 3
defaultContentLanguage = 'en'
[languages]
[languages.de]
contentDir = 'content/de'
languageCode = 'de-DE'
languageName = 'Deutsch'
weight = 2
[languages.en]
contentDir = 'content/en'
languageCode = 'en-US'
languageName = 'English'
weight = 1
[languages.fr]
contentDir = 'content/fr'
languageCode = 'fr-FR'
languageName = 'Français'
weight = 3
{
"defaultContentLanguage": "en",
"languages": {
"de": {
"contentDir": "content/de",
"languageCode": "de-DE",
"languageName": "Deutsch",
"weight": 2
},
"en": {
"contentDir": "content/en",
"languageCode": "en-US",
"languageName": "English",
"weight": 1
},
"fr": {
"contentDir": "content/fr",
"languageCode": "fr-FR",
"languageName": "Français",
"weight": 3
}
}
}
And this content:
content/
├── de/
│ ├── books/
│ │ ├── book-1.md
│ │ └── book-2.md
│ └── _index.md
├── en/
│ ├── books/
│ │ ├── book-1.md
│ │ └── book-2.md
│ └── _index.md
├── fr/
│ ├── books/
│ │ └── book-1.md
│ └── _index.md
└── _index.md
And this template:
{{ with .Translations }}
<ul>
{{ range . }}
<li>
<a href="{{ .RelPermalink }}" hreflang="{{ .Language.LanguageCode }}">{{ .LinkTitle }} ({{ or .Language.LanguageName .Language.Lang }})</a>
</li>
{{ end }}
</ul>
{{ end }}
Hugo will render this list on the “Book 1” page of the English site:
<ul>
<li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
<li><a href="/fr/books/book-1/" hreflang="fr-FR">Book 1 (Français)</a></li>
</ul>
Hugo will render this list on the “Book 2” page of the English site:
<ul>
<li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
</ul>