Page

TranslationKey

返回给定页面的翻译 key。

签名
PAGE.TranslationKey
返回类型
string

翻译 key 在给定页面的所有译文之间建立关联。翻译 key 由文件路径推导而来;如果前置元数据中定义了 translationKey 参数,则由该参数决定。

项目配置如下:

defaultContentLanguage = 'en'

[languages.en]
contentDir = 'content/en'
label = 'English'
locale = 'en-US'
weight = 1

[languages.de]
contentDir = 'content/de'
label = 'Deutsch'
locale = 'de-DE'
weight = 2

内容如下:

content/
├── de/
│   ├── books/
│   │   ├── buch-1.md
│   │   └── book-2.md
│   └── _index.md
├── en/
│   ├── books/
│   │   ├── book-1.md
│   │   └── book-2.md
│   └── _index.md
└── _index.md

前置元数据如下:

title = 'Book 1'
translationKey = 'foo'
title = 'Buch 1'
translationKey = 'foo'

渲染上述任一页面时:

{{ .TranslationKey }} → page/foo

如果两种语言中 Book 2 的前置元数据都没有包含翻译 key:

{{ .TranslationKey }} → page/books/book-2