TranslationKey
翻譯鍵在所有翻譯之間創建一種關聯。翻譯鍵是從文件路徑推導出來的,如果前置內容中有定義 translationKey 參數,則使用該參數。
如果您的網站配置如下:
defaultContentLanguage = 'en'
[languages.en]
contentDir = 'content/en'
languageCode = 'en-US'
languageName = 'English'
weight = 1
[languages.de]
contentDir = 'content/de'
languageCode = 'de-DE'
languageName = 'Deutsch'
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
假設對於 content/en/books/book-1.md 和 content/de/books/buch-1.md 的前置內容如下所示:
        content/en/books/book-1.md
      
      
       
      
       
      
       
  ---
title: Book 1
translationKey: foo
---+++
title = 'Book 1'
translationKey = 'foo'
+++{
   "title": "Book 1",
   "translationKey": "foo"
}
        content/de/books/buch-1.md
      
      
       
      
       
      
       
  ---
title: Buch 1
translationKey: foo
---+++
title = 'Buch 1'
translationKey = 'foo'
+++{
   "title": "Buch 1",
   "translationKey": "foo"
}
渲染任意一個頁面時,將返回以下翻譯鍵:
```go-html-template
{{ .TranslationKey }} → page/foo
如果 book-2 的前置內容中未包括翻譯鍵,無論語言如何,則翻譯鍵會基於文件路徑返回:
{{ .TranslationKey }} → page/books/book-2