翻译
Syntax
PAGE.Translations
Returns
page.Pages
使用以下站点配置:
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
}
}
}
以及以下内容:
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 .Translations }}
<ul>
{{ range . }}
{{ $lang := .Language.LanguageName}}
<li><a href="{{ .RelPermalink }}">{{ .LinkTitle }} ({{ $lang }})</a></li>
{{ end }}
</ul>
{{ end }}
Hugo 将在英文站点的 “Book 1” 页面上呈现以下列表:
<ul>
<li><a href="/de/books/book-1/">Book 1 (Deutsch)</a></li>
<li><a href="/fr/books/book-1/">Book 1 (Français)</a></li>
</ul>
Hugo 将在英文站点的 “Book 2” 页面上呈现以下列表:
<ul>
<li><a href="/de/books/book-1/">Book 1 (Deutsch)</a></li>
</ul>