Framework-integratie
Stapsgewijze configuratie voor i18n-rosetta met populaire frameworks.
- Hugo
- Next.js (next-intl)
- React (react-i18next)
Hugo (TOML / YAML / Markdown)
Projectstructuur
Hugo gebruikt i18n/ voor stringvertalingen en content/ voor pagina-inhoud:
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
Configuratie
npm install --save-dev i18n-rosetta
{
"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
Details van contentvertaling
Front matter: Ondersteunt zowel YAML- (---) als TOML-scheidingstekens (+++). Vertaalt standaard title, description, summary, subtitle, caption en linkTitle. Alle andere velden (date, draft, tags, weight, slug, enz.) blijven behouden. U kunt dit aanpassen met translatableFields in uw configuratie.
Blokbescherming: Codeblokken, Hugo-shortcodes, inline code en ruwe HTML worden automatisch afgeschermd met behulp van Unicode-sentinel-placeholders. Deze worden ongewijzigd doorgegeven.
Bestandsnaamconventie: Volgt Hugo's patroon voor vertaling via bestandsnamen:
my-post.md→my-post.fr.mdmy-post.en.md→my-post.fr.md(verwijdert het achtervoegsel van de bron)
Bestaande overslaan: Bestaande vertaalde bestanden worden nooit overschreven. Verwijder een doelbestand om een hervertaling af te dwingen.
Meervoudsvormen
TOML- en YAML-locales ondersteunen CLDR-meervoudsvormen:
[items]
one = "{{ .Count }} item"
other = "{{ .Count }} items"
Intern weergegeven als items.one en items.other voor diffing, en vervolgens bij het wegschrijven opnieuw geserialiseerd naar het correcte, in secties verdeelde formaat.
next-intl (JSON)
Projectstructuur
my-app/
├── messages/
│ └── en.json ← source of truth
├── src/
│ ├── i18n/
│ │ ├── routing.ts
│ │ └── request.ts
│ └── middleware.ts
└── .env.local
Configuratie
npm install --save-dev i18n-rosetta
{
"version": 3,
"inputLocale": "en",
"localesDir": "./messages",
"languages": ["fr", "de", "ja", "es", "ko", "zh", "pt", "ar"]
}
npx i18n-rosetta sync
Creëert messages/fr.json, messages/ja.json, enz. — volledig vertaald, met behoud van uw geneste sleutelstructuur. next-intl pakt deze automatisch op.
Ontwikkelingsworkflow
{
"scripts": {
"dev": "i18n-rosetta watch & next dev",
"i18n:sync": "i18n-rosetta sync",
"i18n:audit": "i18n-rosetta audit"
}
}
react-i18next (JSON)
Platte bestandsstructuur (aanbevolen)
locales/
├── en.json
├── fr.json
└── ja.json
{
"version": 3,
"inputLocale": "en",
"localesDir": "./locales",
"languages": ["fr", "de", "ja"]
}
npx i18n-rosetta sync
Geneste mappenstructuur
Als u de {locale}/{namespace}.json-structuur gebruikt, maak dan een synchronisatiescript aan om te flatten → vertalen → unflatten. Raadpleeg de react-i18next-documentatie voor meer details.