Mag-skip sa main content

Cookbook: Hugo Multilingual Site

I-set up ang multilingual system ng Hugo gamit ang i18n-rosetta para i-handle ang parehong JSON string files at Markdown content translation. Cino-cover nito ang kumpletong workflow mula sa project setup hanggang sa production deployment.

Ano ang ibi-build mo: Isang Hugo site na may English, French, at Japanese — string translations via locale files, at content translations via Markdown processing.


Project Structure

Gumagamit ang Rosetta ng filename-based translation mode ng Hugo. Ang mga translated files ay inilalagay sa parehong directory ng source file, na may language suffix na idinagdag sa filename (e.g. about.fr.md):

my-hugo-site/
├── content/
│ └── en/
│ ├── _index.md
│ ├── _index.fr.md ← rosetta generates
│ ├── _index.ja.md ← rosetta generates
│ ├── about.md
│ ├── about.fr.md ← rosetta generates
│ ├── about.ja.md ← rosetta generates
│ └── blog/
│ ├── first-post.md
│ ├── first-post.fr.md ← rosetta generates
│ └── first-post.ja.md ← rosetta generates
├── i18n/
│ ├── en.json
│ ├── fr.json ← rosetta generates
│ └── ja.json ← rosetta generates
└── hugo.toml

:::note Hugo i18n Modes Sinusuportahan ng Hugo ang dalawang translation strategies: filename-based (about.fr.md next to about.md) at directory-based (separate content/fr/about.md trees). Gumagamit ang Rosetta ng filename-based translation dahil ang getTargetContentPath() function nito ay nagge-generate ng target paths sa pamamagitan ng pag-append ng language suffix sa source filename. Siguraduhin po na ang inyong hugo.toml ay naka-configure para sa filename-based translation kapag gumagamit ng rosetta. :::

Step 1: I-configure ang Hugo

hugo.toml
defaultContentLanguage = 'en'

[languages]
[languages.en]
languageName = 'English'
weight = 1
[languages.fr]
languageName = 'Français'
weight = 2
[languages.ja]
languageName = '日本語'
weight = 3

Step 2: I-configure ang Rosetta

Kailangan ng Rosetta ng dalawang bagay na naka-configure: ang locale file path (para sa JSON strings) at ang content directory (para sa Markdown).

i18n-rosetta.config.json
{
"version": 3,
"inputLocale": "en",
"localesDir": "./i18n",
"contentDir": "./content",
"model": "google/gemini-3.5-flash",
"pairs": {
"en:fr": { "method": "llm" },
"en:ja": { "method": "llm", "model": "openai/gpt-4o" }
},
"languages": {
"fr": { "name": "French", "register": "Formal (vous-form)" },
"ja": { "name": "Japanese", "register": "Polite/formal" }
}
}

Step 3: Gumawa ng Source Content

String Translations (i18n/)

i18n/en.json
{
"nav": {
"home": "Home",
"about": "About",
"blog": "Blog",
"contact": "Contact"
},
"footer": {
"copyright": "© 2026 My Company. All rights reserved.",
"privacy": "Privacy Policy"
}
}

Markdown Content (content/en/)

content/en/about.md
---
title: "About Us"
description: "Learn more about our team and mission"
date: 2026-01-15
---

We build software that helps businesses communicate across languages.

Our platform supports **real-time translation** for over 30 languages,
with specialized support for low-resource languages.

## Our Mission

Language should never be a barrier to understanding.

## The Team

{{< team-grid >}}

Step 4: I-run ang Sync

npx i18n-rosetta sync

Pino-process ng Rosetta ang parehong types:

  1. String files (i18n/en.jsoni18n/fr.json, i18n/ja.json)
  2. Content files (content/en/about.mdcontent/en/about.fr.md, content/en/about.ja.md)

Content Translation Details

Kapag nagta-translate ng Markdown, ang rosetta ay awtomatikong:

  • Nagsi-shield ng code blocks, shortcodes ({{< ... >}}), inline code, at HTML
  • Nagta-translate ng front matter fields (title, description, summary)
  • Nagpe-preserve ng lahat ng iba pang front matter fields (date, draft, weight, tags)
  • Nagre-restore ng shielded blocks pagkatapos ng translation

Ang Hugo shortcode na {{< team-grid >}} ay nagpa-pass through nang hindi nata-translate.

Step 5: I-verify

# Preview the site
hugo server

# Check translation status
npx i18n-rosetta status

Mag-navigate sa localhost:1313/fr/ at localhost:1313/ja/ para i-review ang translated content.

Step 6: Hugo Language Switcher

Magdagdag ng language switcher sa inyong Hugo layout:

layouts/partials/language-switcher.html
<nav class="language-switcher">
{{ range $.Site.Home.AllTranslations }}
<a href="{{ .Permalink }}"
{{ if eq .Lang $.Site.Language.Lang }}class="active"{{ end }}>
{{ .Language.LanguageName }}
</a>
{{ end }}
</nav>

Pag-keep ng Content in Sync

Kapag nag-update po kayo ng English content, i-run ulit ang sync. Ire-retranslate lang ng Rosetta ang mga files na may changes:

# Edit content/en/about.md, then:
npx i18n-rosetta sync

Tinatrack ng lock file ang content hashes per file, kaya hindi na nire-retranslate ang mga stable pages.

Tingnan Din