Multilingual

Each language is a separate Hugo site with its own menus, parameters, feeds and search index. Icy adds a language switch to the header and the alternate links search engines need. This site is bilingual: try the 中 / EN switch in the header.

Languages

Declare each language under [languages]. The top-level [params] is shared. Put what differs into the language’s own params and menus:

hugo.toml
defaultContentLanguage = 'en'
hasCJKLanguage = true

[languages]
  [languages.en]
    locale = 'en'
    label = 'English'
    weight = 1
    [languages.en.params]
      description = 'Notes on whatever I am learning.'

  [languages.zh-cn]
    locale = 'zh-CN'
    label = '简体中文'
    weight = 2
    [languages.zh-cn.params]
      description = '学习笔记。'
      languageShort = '中'
      [languages.zh-cn.params.author]
        bio = '一句话介绍。'

[languages.en.menus]
  [[languages.en.menus.main]]
    name = 'Posts'
    pageRef = '/posts'
    weight = 10

[languages.zh-cn.menus]
  [[languages.zh-cn.menus.main]]
    name = '文章'
    pageRef = '/posts'
    weight = 10
KeyDescription
localeThe page’s lang, which also picks the default fonts. Also used for hreflang, og:locale and the RSS language. Defaults to the language key.
labelThe language’s name in the switch, for screen readers and as a tooltip.
directionltr or rtl.
paramsOverrides the top-level [params] key by key. A language that sets only fonts.sans still gets fonts.stylesheets from the top level.
menusThe language’s header and footer menus. pageRef resolves to the page in that language.

Translations

Name a translation after the default-language file, with the language key before the extension:

content/
├── about.md                 English
├── about.zh-cn.md           Simplified Chinese
└── posts/
    └── hello/
        ├── index.md         English
        ├── index.zh-cn.md   Simplified Chinese
        └── photo.jpg        shared by both

Files with the same path are translations of each other. To pair files with different names, give them the same translationKey. A page does not need a translation in every language.

Warning

A page bundle shares its images between translations only when it has an index.md in the default language. A bundle with only index.zh-cn.md cannot find its images, and the build fails. Add a default-language index.md, or write the post as a single file with its images in assets/ or static/.

Language switch

The header shows a short code for each other language. It links to the translation of the current page, or to that language’s home page when there is none.

ParameterDefaultDescription
languageShortfirst two letters of the language key, upper caseThe language’s code in the switch. Set it per language.
hugo.toml
[languages.zh-cn.params]
  languageShort = '中'

The switch takes room in the header, so with several languages the links move into the menu button sooner.

What each language gets

FeatureBehavior
Alternate linksEvery page links its translations with hreflang.
SearchOne index per language. Add a search page in every language, such as search.md and search.zh-cn.md.
RSSOne set of feeds per language: /index.xml, /zh-cn/index.xml …
SitemapOne per language, listed in the sitemap index at /sitemap.xml.
TagsPer language. See Tags.
FontsThe defaults follow the page language. See Fonts per language.
Interface textFrom the i18n file of the language. See Interface strings.