Hugo Narrow 支持创建多语言站点,在导航栏通过按钮切换显示。
目前 Hugo Narrow 支持如下语言:
ar:阿拉伯语de:德语en:英语es:西班牙语fr:法语it:意大利语ja:日语ko:韩语pt:葡萄牙语ru:俄语vi:越南语zh-hans:简体中文zh-hant:繁体中文
NOTE
翻译使用 AI 完成,如果你需要添加或优化你的语言,欢迎提出 issue 或者 PR。
多语言站点首先需要在站点配置默认语言。
yaml
defaultContentLanguage: zh-hans创建翻译配置文件:
yaml
en:
locale: en
label: "English"
weight: 1
# 可选:按语言覆盖站点级 params.yaml 中的 dateFormat
# params:
# dateFormat:
# long: "January 2, 2006"
# medium: "Jan 2, 2006"
# short: "01/02"
zh-hans:
locale: zh-Hans
label: "简体中文"
weight: 2
# 可选:按语言覆盖站点级 params.yaml 中的 dateFormat
# params:
# dateFormat:
# long: "2006年1月2日"
# medium: "2006-01-02"
# short: "01-02"NOTE
通过 params.dateFormat 和 params.timeFormat 参数可设置不同语言的日期和时间格式。
翻译文件
Hugo 支持两种主要的多语言文件组织方式:文件名翻译和目录翻译。每种方式都有其优势和适用场景。
例如,有一篇文章 content/posts/my-first-post.md,可在文件扩展名前指定语言后缀创建 content/posts/my-first-post.zh-hans.md 作为中文翻译。
yaml
content/
├── posts/
│ ├── my-first-post.md
│ ├── my-first-post.zh-cn.md
│ ├── my-first-post.ja.md
│ └── my-first-post.fr.md
├── about/
│ ├── _index.md
│ ├── _index.zh-cn.md
│ ├── _index.ja.md
│ └── _index.fr.md
└── _index.md翻译目录
翻译目录需要指定目录位置:
yaml
languages:
en:
contentDir: content/english
label: English
weight: 10
zh-hans:
contentDir: content/zh-hans
label: 简体中文
weight: 20yaml
content/
├── en/
│ ├── posts/
│ │ └── my-first-post.md
│ ├── about/
│ │ └── _index.md
│ └── _index.md
├── zh-hans/
│ ├── posts/
│ │ └── my-first-post.md
│ ├── about/
│ │ └── _index.md
│ └── _index.md
├── posts/
│ └── my-first-post.md
├── about/
│ └── _index.md
└── _index.mdNOTE
这种方式目录结构有更多层级,请访问 Hugo 文档 了解详细内容。