LanguagePrefix
Syntax
SITE.LanguagePrefix
Returns
string
考虑以下网站配置:
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
}
}
}
访问德语语言网站时:
{{ .Site.LanguagePrefix }} → ""
访问英语语言网站时:
{{ .Site.LanguagePrefix }} → /en
如果将 defaultContentLanguageInSubdir
更改为 true
,访问德语语言网站时:
{{ .Site.LanguagePrefix }} → /de
您可以在使用单语言和多语言网站时都使用 LanguagePrefix
方法。