Hugo Narrow 支持创建多语言站点,在导航栏通过按钮切换显示。

目前 Hugo Narrow 支持如下语言:

  • ar:阿拉伯语
  • de:德语
  • en:英语
  • es:西班牙语
  • fr:法语
  • it:意大利语
  • ja:日语
  • ko:韩语
  • pt:葡萄牙语
  • ru:俄语
  • vi:越南语
  • zh-cn:简体中文
  • zh-tw:繁体中文

多语言站点首先需要在站点配置默认语言。

hugo.yaml
1defaultContentLanguage: zh-cn
点击展开查看更多

创建翻译配置文件:

languages.yaml
 1en:
 2  languageCode: en-US
 3  languageName: "English"
 4  weight: 1
 5
 6zh-cn:
 7  languageCode: zh-CN
 8  languageName: "简体中文"
 9  weight: 2
10
11ja:
12  languageCode: ja-JP
13  languageName: "日本語"
14  weight: 3
15
16fr:
17  languageCode: fr-FR
18  languageName: "Français"
19  weight: 4
点击展开查看更多

Hugo 支持两种主要的多语言文件组织方式:文件名翻译目录翻译。每种方式都有其优势和适用场景。

翻译文件

例如,有一篇文章 content/posts/my-first-post.md,可在文件扩展名前指定语言后缀创建 content/posts/my-first-post.zh-cn.md 作为中文翻译。

YAML
 1content/
 2├── posts/
 3│   ├── my-first-post.md
 4│   ├── my-first-post.zh-cn.md
 5│   ├── my-first-post.ja.md
 6│   └── my-first-post.fr.md
 7├── about/
 8│   ├── _index.md
 9│   ├── _index.zh-cn.md
10│   ├── _index.ja.md
11│   └── _index.fr.md
12└── _index.md
点击展开查看更多

翻译目录

翻译目录需要指定目录位置:

languages.yaml
1languages:
2  en:
3    contentDir: content/english
4    languageName: English
5    weight: 10
6  zh-CN:
7    contentDir: content/zh-CN
8    languageName: 简体中文
9    weight: 20
点击展开查看更多
YAML
 1content/
 2├── en/
 3│   ├── posts/
 4│   │   └── my-first-post.md
 5│   ├── about/
 6│   │   └── _index.md
 7│   └── _index.md
 8├── zh-cn/
 9│   ├── posts/
10│   │   └── my-first-post.md
11│   ├── about/
12│   │   └── _index.md
13│   └── _index.md
14├── ja/
15│   ├── posts/
16│   │   └── my-first-post.md
17│   ├── about/
18│   │   └── _index.md
19│   └── _index.md
20└── fr/
21├── posts/
22│   └── my-first-post.md
23├── about/
24│   └── _index.md
25└── _index.md
点击展开查看更多

版权声明

作者: Hugo Narrow

链接: https://hugo-narrow-docs.vercel.app/zh-cn/docs/multilingual/

许可证: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Please attribute the source, use non-commercially, and maintain the same license.

开始搜索

输入关键词搜索文章内容

↑↓
ESC
⌘K 快捷键