AllTranslations
Syntax
PAGE.AllTranslations
Returns
page.Pages
使用以下站点配置:
hugo.
defaultContentLanguage: en
languages:
de:
contentDir: content/de
languageCode: de-DE
languageName: 德文
weight: 2
en:
contentDir: content/en
languageCode: en-US
languageName: 英文
weight: 1
fr:
contentDir: content/fr
languageCode: fr-FR
languageName: 法文
weight: 3
defaultContentLanguage = 'en'
[languages]
[languages.de]
contentDir = 'content/de'
languageCode = 'de-DE'
languageName = '德文'
weight = 2
[languages.en]
contentDir = 'content/en'
languageCode = 'en-US'
languageName = '英文'
weight = 1
[languages.fr]
contentDir = 'content/fr'
languageCode = 'fr-FR'
languageName = '法文'
weight = 3
{
"defaultContentLanguage": "en",
"languages": {
"de": {
"contentDir": "content/de",
"languageCode": "de-DE",
"languageName": "德文",
"weight": 2
},
"en": {
"contentDir": "content/en",
"languageCode": "en-US",
"languageName": "英文",
"weight": 1
},
"fr": {
"contentDir": "content/fr",
"languageCode": "fr-FR",
"languageName": "法文",
"weight": 3
}
}
}
以及下列内容:
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
以及下列模板:
{{ with .AllTranslations }}
<ul>
{{ range . }}
{{ $lang := .Language.LanguageName}}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }} ({{ $lang }})</a></li>
{{ end }}
</ul>
{{ end }}
Hugo将在每个语言站点的"Book 1"页面上渲染以下列表:
<ul>
<li><a href="/books/book-1/">图书 1 (英文)</a></li>
<li><a href="/de/books/book-1/">图书 1 (德文)</a></li>
<li><a href="/fr/books/book-1/">图书 1 (法文)</a></li>
</ul>
在英文和德文站点的"Book 2"页面上,Hugo将渲染以下内容:
<ul>
<li><a href="/books/book-1/">图书 1 (英文)</a></li>
<li><a href="/de/books/book-1/">图书 1 (德文)</a></li>
</ul>