Mag-skip sa main content

Framework Integration

Step-by-step setup para sa i18n-rosetta kasama ang mga popular na frameworks.

Hugo (TOML / YAML / Markdown)

Project Structure

Gumagamit ang Hugo ng i18n/ para sa string translations at content/ para sa 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: Sinusuportahan ang parehong YAML (---) at TOML (+++) delimiters. Tina-translate ang title, description, summary, subtitle, caption, at linkTitle by default. Ang lahat ng iba pang fields (date, draft, tags, weight, slug, etc.) ay naka-preserve. I-customize gamit ang translatableFields sa iyong config.

Block protection: Ang mga code blocks, Hugo shortcodes, inline code, at raw HTML ay automatically shielded gamit ang Unicode sentinel placeholders. Ipapasa lang ang mga ito nang untouched.

Filename convention: Sinusundan ang translation-by-filename pattern ng Hugo:

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

Skip existing: Ang mga existing translated files ay hindi kailanman ino-overwrite. I-delete ang isang target file para i-force ang re-translation.

Plural Forms

Sinusuportahan ng TOML at YAML locales ang CLDR plural forms:

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

Internally represented ito bilang items.one at items.other para sa diffing, tapos ire-re-serialize sa tamang sectioned format kapag nag-write.