How to enable i18n routing for a page

Pages opt into i18n routing one at a time. Without SupportedLocales, a page receives a single route under the default locale, even when global i18n configuration enables multi-locale routing. For the routing primitives see routing rules reference. For the i18n service surface see i18n API reference. For the rationale behind opt-in see about i18n.

Note: Multi-locale routing is page-scoped, not project-scoped. Setting I18n.Locales via piko.WithWebsiteConfig(...) enables the strategy; adding SupportedLocales() to a page is what makes that page emit one route per locale.

Declare the page's supported locales

Add a SupportedLocales function to the page's <script type="application/x-go"> block:

// SupportedLocales enables i18n routing for this page.
// One route is generated for each locale listed here.
func SupportedLocales() []string {
    return []string{"en", "fr", "de"}
}

The router reads this list at build time and registers a route per locale, using the global i18n routing strategy (see How to choose a routing strategy).

Resulting routes under prefix_except_default

For a page at pages/about.pk with the default English locale:

  • en (default): /about
  • fr: /fr/about
  • de: /de/about

Switching the strategy to prefix adds the prefix to every locale, including the default. Switching to query-only (the Piko default) keeps a single bare path and reads the locale from a query parameter or detection. disabled turns multi-locale routing off entirely.

Combine with dynamic segments

Dynamic segments compose with locale prefixes:

// pages/blog/{slug}.pk
func SupportedLocales() []string {
    return []string{"en", "fr"}
}

Generates /blog/{slug} and /fr/blog/{slug}. The locale resolves before parameter binding, so the action sees the bound slug regardless of locale.

See also