语言
Syntax
SITE.Languages
Returns
langs.Languages
Languages
方法在 Site
对象上返回按语言权重排序的所有站点的语言对象集合。每个语言对象指向站点配置中的语言定义。
要查看数据结构:
<pre>{{ jsonify (dict "indent" " ") .Site.Languages }}</pre>
使用以下站点配置:
hugo.
defaultContentLanguage: de
defaultContentLanguageInSubdir: false
languages:
de:
languageCode: de-DE
languageDirection: ltr
languageName: Deutsch
title: Projekt Dokumentation
weight: 1
en:
languageCode: en-US
languageDirection: ltr
languageName: English
title: Project Documentation
weight: 2
defaultContentLanguage = 'de'
defaultContentLanguageInSubdir = false
[languages]
[languages.de]
languageCode = 'de-DE'
languageDirection = 'ltr'
languageName = 'Deutsch'
title = 'Projekt Dokumentation'
weight = 1
[languages.en]
languageCode = 'en-US'
languageDirection = 'ltr'
languageName = 'English'
title = 'Project Documentation'
weight = 2
{
"defaultContentLanguage": "de",
"defaultContentLanguageInSubdir": false,
"languages": {
"de": {
"languageCode": "de-DE",
"languageDirection": "ltr",
"languageName": "Deutsch",
"title": "Projekt Dokumentation",
"weight": 1
},
"en": {
"languageCode": "en-US",
"languageDirection": "ltr",
"languageName": "English",
"title": "Project Documentation",
"weight": 2
}
}
}
该模板:
<ul>
{{ range .Site.Languages }}
<li>{{ .Title }} ({{ .LanguageName }})</li>
{{ end }}
</ul>
渲染为:
<ul>
<li>Projekt Dokumentation (Deutsch)</li>
<li>Project Documentation (English)</li>
</ul>