Saltar al contenido principal

Framework Integration

Step-by-step setup for i18n-rosetta with popular frameworks.

Hugo (TOML / YAML / Markdown)

Project Structure

Hugo uses i18n/ for string translations and content/ for page content:

my-hugo-site/
├── i18n/
│ ├── en.toml ← source of truth
│ ├── fr.toml
│ └── ja.toml
├── content/
│ ├── posts/
│ │ ├── hello.md ← source (English)
│ │ ├── hello.fr.md
│ │ └── hello.ja.md
│ └── about.md
└── .env.local

Setup

npm install --save-dev i18n-rosetta
i18n-rosetta.config.json
{
"version": 3,
"inputLocale": "en",
"localesDir": "./i18n",
"contentDir": "./content",
"format": "auto",
"languages": ["fr", "de", "ja", "es", "ko", "zh"]
}
i18n-rosetta sync # sync i18n string files + content files
i18n-rosetta sync --dry # preview changes without writing

Content Translation Details

Front matter: Supports both YAML (---) and TOML (+++) delimiters. Translates title, description, summary, subtitle, caption, and linkTitle by default. All other fields (date, draft, tags, weight, slug, etc.) are preserved. Customize with translatableFields in your config.

Block protection: Code blocks, Hugo shortcodes, inline code, and raw HTML are automatically shielded using Unicode sentinel placeholders. They pass through untouched.

Filename convention: Follows Hugo's translation-by-filename pattern:

  • my-post.mdmy-post.fr.md
  • my-post.en.mdmy-post.fr.md (strips source suffix)

Skip existing: Existing translated files are never overwritten. Delete a target file to force re-translation.

Plural Forms

TOML and YAML locales support CLDR plural forms:

[items]
one = "{{ .Count }} item"
other = "{{ .Count }} items"

Internally represented as items.one and items.other for diffing, then re-serialized to the correct sectioned format on write.