Skip to content

@bongo/i18n, and config partials with page values #58

Description

@lukeed

Depends on #57 ($hooks.page).

A plugin can ship config partials ($partials), but today those get only their arguments, while a file partial in partials/ also gets $page, $pages, $section, and $tags. This issue makes config partials see page values, and builds @bongo/i18n on that and on $hooks.page.

Core: config partials get page values

Today a $partials function gets only its arguments, while a file partial in partials/ also gets $page, $pages, $section, and $tags. A plugin can ship only config partials. So config partials should get the same values as file partials, merged the same way: page values, then arguments, then the config ($site, $utils, $data, $assets). Calls from Markdown or a loader still get no page values, as for file partials. An existing $partials function only sees more keys.

Plugin: @bongo/i18n

import { i18n } from '@bongo/i18n';

export default {
	$site: { url: 'https://example.com/', title: 'My site', lang: 'en' },
	plugins: [i18n({ languages: { en: '/', fr: '/fr/', de: '/de/' } })],
};
  • languages maps each language to the folder of its pages. The language of $site.lang is the default, and the x-default.
  • The language of a page comes from its folder, or from lang in its frontmatter.
  • Translations match by their path without the language folder (/fr/contact/ and /contact/ are both /contact/), or by a shared key in frontmatter when the slugs differ.

The plugin's page hook sets, for example on /fr/a-propos/:

{
	title: 'À propos',
	key: 'about',
	lang: 'fr',
	versions: [
		{ lang: 'en', path: '/about/', url: 'https://example.com/about/', title: 'About' },
		{ lang: 'fr', path: '/fr/a-propos/', url: 'https://example.com/fr/a-propos/', title: 'À propos' },
	],
}

versions lists every version, the page itself included, in the order of languages, as hreflang needs. A page with no translation has only itself.

Templates:

<html lang="{{ $page.params.lang }}">
<head>
	{{#partial src="hreflang"}}
</head>
<body>
	{{#each $page.params.versions.filter(v => v.lang !== $page.params.lang) as v}}
	<a href="{{ v.path }}" hreflang="{{ v.lang }}" lang="{{ v.lang }}">{{ v.title }}</a>
	{{/each}}

{{#partial src="hreflang"}} writes one <link rel="alternate" hreflang> for each version, plus x-default, and nothing for a page with no translation. A sitemap loops page.params.versions for its xhtml:link elements. Layout text stays in data/.

Today (Translations guide) With the hook and the plugin
A page's language lang: in each translated page from its folder
Matching key: in each page by path; key: only when slugs differ
hreflang in the layout about 8 lines of expressions {{#partial src="hreflang"}}
Work per build pages × pages pages (one index)

Benchmark

Use the benchmark from #57. Generate a two-language version of the large site, and record the time and the peak memory of bongo build with @bongo/i18n, next to the numbers of #57. The plugin must build its translation index once per build, so its work grows with the page count, not with pages × pages.

Work

  • Config partials get page values, with tests
  • @bongo/i18n, with tests
  • The Translations guide shows the plugin first, and the plain version for sites without it
  • Benchmark with the plugin, numbers in the PR

Activity

  1. added
    enhancement
    on Oct 15, 2026
  2. added theissue type on Oct 20, 2026
  3. removed
    enhancement
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions