Multilingual Configuration

Previously, we had a rough understanding of Hugo’s configuration structure, and then we will introduce how to configure multilingual sites.

Site Configuration

NameDescription
defaultContentLanguageThe default site language.
defaultContentLanguageInSubdirWhether URLs for the default language contain language code, eg /en.

hugo.toml

1defaultContentLanguage = 'en'
2defaultContentLanguageInSubdir = true

hugo.yaml

1defaultContentLanguage: en
2defaultContentLanguageInSubdir: true

hugo.json

1{
2   "defaultContentLanguage": "en",
3   "defaultContentLanguageInSubdir": true
4}

Language Entry Properties

NameDescription
languageNameName
languageDirectionLanguage direction, such as rlt.
weightLower weight gets higher precedence.
titleSite’s title.
copyrightSite’s copyright.

Multilingual Configuration

languages.toml

 1[ar]
 2  languageDirection = 'rtl'
 3  languageName = 'العربية'
 4  weight = 4
 5[en]
 6  languageName = 'English'
 7  weight = 1
 8[zh-hans]
 9  languageName = '简体中文'
10  title = 'HB (Hugo Bootstrap) 框架'
11  weight = 2

languages.yaml

 1ar:
 2  languageDirection: rtl
 3  languageName: العربية
 4  weight: 4
 5en:
 6  languageName: English
 7  weight: 1
 8zh-hans:
 9  languageName: 简体中文
10  title: HB (Hugo Bootstrap) 框架
11  weight: 2

languages.json

 1{
 2   "ar": {
 3      "languageDirection": "rtl",
 4      "languageName": "العربية",
 5      "weight": 4
 6   },
 7   "en": {
 8      "languageName": "English",
 9      "weight": 1
10   },
11   "zh-hans": {
12      "languageName": "简体中文",
13      "title": "HB (Hugo Bootstrap) 框架",
14      "weight": 2
15   }
16}

Multilingual Params and Menus

You may want to configure some stuff for each language, such as description, and to do this, simply create language-specific configuration files, such as:

ConfigurationDescription
menus.en.*English site’s menus.
params.en.*English site’s params.
menus.zh-hans.*Chinese site’s menus.
params.zh-hans.*Chinese site’s params.

Learn more on Hugo Multilingual Mode.

razonyang
Thursday, November 21, 2024 Saturday, February 18, 2023