Languages
OINK uses Hugo’s multilingual model as it is: a languages block in
hugo.yml, and each translation saved beside its original with a language
suffix. Adding a language touches five places: the configuration, the
translated pages, the menus, the home page data and, only if you want to
reword them, the theme’s interface strings. The language picker, hreflang
links and per-language search follow from those without further setup.
Enable a second language
labelis the name in the language picker, written in that language:简体中文, notChinese.localeis the standard language tag used for<html lang>, thehreflangalternate links and Open Graph metadata.weightorders the languages, lowest first, in the picker and in its one-click cycle.paramsoverrides site parameters for this language; any key not set here keeps the global value. Date formats usually need a per-language value.
The default language is served without a path prefix (English at /docs/…)
and every other language under its own (Chinese at /zh/docs/…). To prefix
the default language too, add defaultContentLanguageInSubdir: true; on a
live site this changes every URL, so set up redirects at the same time.
Translate the pages
Save each translation beside its original with the language code before the extension. Hugo pairs files that share a base name, so these are one page in two languages:
content/docs/
- install.mdEnglish
- install.zh.mdChinese
- _index.md
- _index.zh.md
Page bundles work the same way, with index.md and index.zh.md in one
directory. Inside a bundle, a resource without a language suffix is shared by
every language and a suffixed one belongs to that language only. Reference a
suffixed resource without its suffix, , and
Hugo picks the file for the current language:
content/docs/install/
- index.mdEnglish page
- index.zh.mdChinese page
- topology.webpused by both languages
- screenshot.zh.webpused by the Chinese page only
A bundle that has only index.zh.md needs the .zh. suffix on every
resource. Unsuffixed resources belong to the default language, which has no
page in that bundle, so the Chinese page would not see them.
Translate what readers see and keep what Hugo uses for structure identical:
- Translate:
title,description, summaries, menu labels, tag names, image alt text, callout bodies and reader-facing shortcode parameters. - Keep identical: dates,
weight, aliases and anything else that affects routing or order; a differentweightputs the page in a different sidebar position in each language. - Leave untranslated: commands, configuration keys, file names, URLs, version numbers, product names and shortcode names.
Menus, home page and interface strings
Three things live outside content/ and need one copy per language.
Menus are written under each language:
Use the same identifier in every language, because the command palette’s
quick links and the grouping of search results are matched by it. The full
menu syntax is in Navigation and menus.
Home page data is one file per language, data/home/en.yaml and
data/home/zh.yaml; a language without a file falls back to en.yaml. See
Home and landing pages.
Interface strings, such as the search placeholder and the page-action
labels, are already translated: the theme ships complete, native catalogs for
32 locales (ar, az, bg, bn, de, en, es, et, fa, fi, fr,
he, hi, hu, it, ja, ko, nl, no, oc, pl, pt-br, ro,
ru, sr-cyrl, sr-latn, sv, tr, uk, zh, zh-cn and zh-tw).
zh and zh-cn are Simplified Chinese and zh-tw Traditional. To reword a
string, create a file of the same name in the site’s own i18n/ with only the
keys you change; key names are in the theme’s i18n/en.yaml, and any
placeholder such as {{ .Count }} in the original must stay in your version.
Align heading anchors
Hugo derives a heading’s ID from its text, so a translated heading gets a
different ID: /docs/install/#prerequisites and /zh/docs/install/#前置条件
are the same section under two anchors. A deep link copied from one language
then fails in the other, every cross-reference has to be written twice, and
Duo View cannot keep its two panes at the same section.
Give the translated heading the original’s ID explicitly:
Take the ID from the English page’s rendered HTML rather than guessing it from
the heading text, because inline code, badges and shortcodes in a heading
change the generated ID. Keep the same headings, in the same order, with the
same IDs on both sides; a section that exists in only one language gets its own
stable ID that does not collide with the other’s. Adding {#id} when you
write a page costs far less than retrofitting it.
To compare one translated pair after a build:
To check every pair in CI, the OINK documentation site runs
check-doc-translations.mjs,
which compares source structure and rendered heading IDs. It is written for
that repository’s content sections and EN/ZH file names, so adapt both before
running it on another site.
Missing translations and the language picker
The language picker’s icon is itself a link to the next language by weight,
wrapping round after the last, so a bilingual site switches with one click.
Hovering over it or focusing it opens a menu of every language; on a touch
screen a tap switches directly.
The menu always lists every configured language. Choosing one opens the translation of the current page when there is one, and that language’s home page when there is not. The home page beats a 404, but readers may not notice they have moved, so treat “every page has a translation” as a rule to check rather than relying on the fallback.
If a page has no Chinese version, the Chinese site has no such page: its sidebar, search index and page order leave it out.
Search engines see only real translations: hreflang lists the current page
and its actual translations, never the home page fallback. See
canonical URLs and language alternates.
Local search also works per language, so a search on a Chinese page finds
Chinese content, including unspaced Chinese, mixed-language queries and
technical identifiers; see Search.
Duo view
Duo View lets a reader open a page beside one of its translations, which helps anyone checking a translation or reading in a second language. Turn it on with:
On Docs, Book and blog pages with a published translation on the same site,
an Open duo view button appears beside the page actions. Readers can also
start Duo View from the command palette, or press B when
keyboard navigation is on (try it on this page), and press B
again to return. The current page stays on the side where reading starts and
the other pane loads the translation; on a page with more than two languages,
readers pick the target language from the toolbar menu. Below 900px the view
becomes a single pane with a language toggle bar.
The Sync Scroll switch keeps both panes at the same section by matching heading IDs, which is why aligned anchors matter here. When some headings have no counterpart, or the pages share none, it estimates the position between matching headings or from overall progress, and an orange ! beside the switch says which; hover, focus or tap it to read the note. When heading IDs are duplicated or ordered differently between the languages, Sync Scroll turns itself off and both panes scroll independently.
Duo View adds no pages to the build: only when a reader opens it does the
browser load the two existing HTML pages, in same-origin frames. Pages without
a translation, drafts, home page fallbacks and translations hosted on another
domain are left out automatically. To keep one language out entirely, both as
the page being read and as the translation shown, set compare: false under
languages.<lang>.params.ui.
Before enabling it in production, check two things:
- Analytics snippets in
hooks/head-end.htmlrun again inside each pane unless you guard them withwindow.OinkComparePane; see Analytics. - Your Content Security Policy must allow
frame-src 'self', and the server must not sendX-Frame-Options: DENYorframe-ancestors 'none'; see Content Security Policy.
Right-to-left languages
Declare the writing direction on the language:
<html dir> follows this setting and the theme adds Bootstrap’s RTL
stylesheet. The theme’s own CSS uses logical properties, such as
margin-inline-start rather than margin-left, so the layout mirrors by
itself. Use logical properties in your own CSS too, or your elements will sit
on the wrong side in RTL.
Verify
-
Build from the site root and confirm that both languages produced output. These paths assume English at
/and Chinese at/zh/; the index check applies only with local search on: -
Check the
hreflanglinks of a translated page against SEO behavior: they list only real translations, each blog pagination page has its own canonical URL, and pages after the first omit language alternates. -
On a translated page, switch language from the picker and confirm that the same document opens; on an untranslated page, confirm that the other language’s home page opens rather than a 404.
-
Search for the same concept in each language and confirm both return results.
-
Compare the heading IDs of a translated pair as shown under Align heading anchors.
Related
- Search — per-language indexes and CJK queries
- Navigation and menus — per-language menus and where the picker sits
- Home and landing pages —
data/home/<lang>.yaml - Writing pages — how to write explicit heading IDs
- Analytics and SEO — how search engines use
hreflangand the sitemap