mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-14 20:37:55 -05:00
9b0050e9aa
git-subtree-dir: docs git-subtree-split: 5c085a37b297bf12f59efeaae591418ec025c10d
2 KiB
2 KiB
title | description | categories | keywords | action | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AllTranslations | Returns all translation of the given page, including the given page. |
|
With this site configuration:
{{< code-toggle file=hugo >}} defaultContentLanguage = 'en'
[languages.en] contentDir = 'content/en' languageCode = 'en-US' languageName = 'English' weight = 1
[languages.de] contentDir = 'content/de' languageCode = 'de-DE' languageName = 'Deutsch' weight = 2
[languages.fr] contentDir = 'content/fr' languageCode = 'fr-FR' languageName = 'Français' weight = 3 {{< /code-toggle >}}
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 .AllTranslations }}
<ul>
{{ range . }}
{{ $langName := or .Language.LanguageName .Language.Lang }}
{{ $langCode := or .Language.LanguageCode .Language.Lang }}
<li><a href="{{ .RelPermalink }}" hreflang="{{ $langCode }}">{{ .LinkTitle }} ({{ $langName }})</a></li>
{{ end }}
</ul>
{{ end }}
Hugo will render this list on the "Book 1" page of each site:
<ul>
<li><a href="/books/book-1/" hreflang="en-US">Book 1 (English)</a></li>
<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>
On the "Book 2" page of the English and German sites, Hugo will render this:
<ul>
<li><a href="/books/book-1/" hreflang="en-US">Book 1 (English)</a></li>
<li><a href="/de/books/book-1/" hreflang="de-DE">Book 1 (Deutsch)</a></li>
</ul>