Skip to content
Honmaple
Documentation navigation

Multilingual Content

On this page

Snow supports multiple content languages through filename suffixes or front matter.

Configuration

language: "zh"
languages:
  en:
    translations: "i18n/en.yaml"
  fr:
    translations: "i18n/fr.yaml"

languages.{lang} can override global settings such as sections, pages, taxonomies, and base_url.

Language Detection

Language is selected in this order:

  1. The lang front matter field.
  2. A filename suffix, such as hello.en.md.
  3. The site's default language.

Unknown language codes fall back to the default language.

Usage

Filename Suffixes

content/
├── _index.md              # Chinese, the default
├── _index.en.md           # English
├── about.md               # Chinese
└── posts/
    ├── hello.md           # Chinese
    └── hello.en.md        # English

Front Matter

---
title: "Hello World"
lang: "en"
---

Output URLs

Default paths:

content/_index.md          → /index.html
content/_index.en.md       → /en/index.html
content/posts/hello.md     → /posts/hello/
content/posts/hello.en.md  → /en/posts/hello/

Customize paths through configuration:

pages:
  posts:
    path: "articles/{date:%Y}/{date:%m}/{slug}/"
languages:
  en:
    pages:
      posts:
        path: "/english/articles/{date:%Y}/{slug}/"

i18n

Templates

{% i18n "tags" %}
{% T "Total: %d articles" 12 %}
{{ i18n("authors") }}
{{ T("hello %s", "world") }}
{{ _("Total: %.2f", 3.14) }}

i18n, T, and _ are aliases.

Translation Files

# i18n/zh.yaml
---
- id: "authors"
  tr: "作者"
- id: "tags"
  tr: "标签"
# i18n/en.yaml
---
- id: "authors"
  tr: "Authors"
- id: "tags"
  tr: "Tags"

Inline Translations

languages:
  en:
    translations: "i18n/en.yaml"
  zh:
    translations:
      - id: "authors"
        tr: "作者"
      - id: "tags"
        tr: "标签"

translations accepts a file path or an inline array. Files in the theme's i18n/ directory are also loaded automatically.

Cross-Language Lookups

{{ get_page("posts/hello", "en") }}
{{ get_section("posts", "en") }}
{{ get_taxonomy("tags", "en") }}

Omit the language argument to use the current language.