# TranslationKey
> 返回给定页面的翻译 key。
- 官方英文原文：https://gohugo.io/methods/page/translationkey/
- 本页规范地址：https://hugozh.cn/methods/page/translationkey/
- 最近更新：2026-10-02
- 最后提交：912b1d3 chore(site): 添加 static/CNAME（hugozh.cn），供 GitHub Pages 等平台绑定自定义域名
- 签名：PAGE.TranslationKey
- 返回类型：string
- 站点：Hugo 中文文档（https://hugozh.cn/）· 社区维护的非官方中文翻译，如有出入以官方英文原文为准

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

项目配置如下：

```toml
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
```

内容如下：

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

前置元数据如下：

```toml
title = 'Book 1'
translationKey = 'foo'
```

```toml
title = 'Buch 1'
translationKey = 'foo'
```

渲染上述任一页面时：

```go-html-template
{{ .TranslationKey }} → page/foo
```

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

```go-html-template
{{ .TranslationKey }} → page/books/book-2
```

