Contents

Languages

src/i18n/locales.ts is the only list of the site's languages. Payload's localization, the site's routing, the language switcher, hreflang tags, the sitemap and the translation features all read it. As shipped, the kit has English (the default), Danish and German:

export const locales = [
  { code: 'en', label: 'English', hreflang: 'en', ogLocale: 'en_US', isDefault: true },
  { code: 'da', label: 'Dansk', hreflang: 'da', ogLocale: 'da_DK', region: 'DK' },
  { code: 'de', label: 'Deutsch', hreflang: 'de', ogLocale: 'de_DE', region: 'DE' },
] as const satisfies readonly LocaleDef[]
FieldWhat it is
codeWhat appears in addresses (/de/…), in the database and in the API. A language code (de), or a language and region where one language serves several markets (en-GB).
labelThe name in the admin's language picker and the site's language switcher. Write it in the language itself.
hreflangThe BCP 47 tag for <html lang> and hreflang. Dates and numbers are formatted with it.
ogLocaleThe og:locale value, such as da_DK.
isDefaultThe default language: no address prefix, the source of every translation, the fallback for anything not translated, and the words of internal paths (below). Exactly one, and any entry may be it.
regionOptional. The country the language mainly serves, as an ISO 3166 code, used for market defaults such as the dealer locator's starting country.

To add a language, remove one or make another the default, see Add or remove a language. Nothing else in the code names the site's languages.

Addresses #

  • The default language has no prefix: /about. Other languages start with their code: /da/om-os.
  • Every page has a slug per language, made from that language's title the first time it is saved in it, and never changed by itself afterwards. A page's path is its parent's path plus its own slug, in the same language: about/team and om-os/holdet.
  • Collection addresses are localized too. The registry (src/registry/index.ts) gives each collection a segment per language, such as /news and /da/nyheder. A segment without a word for a language uses the default language's. The registry keeps the kit's English, Danish and German words whatever the site's list is; a word for a language the site does not have is never read.
  • Internal paths use the default language's words. A document's internal path (buildHref) and a link to a "Site page" are written in the default language (/news/… with English the default, /nyheder/… with Danish); each language's address is made from them.
  • Wrong-language addresses redirect. A slug or segment from another language is sent permanently to this language's own address.
  • Moves redirect. When a published page gets a new slug or parent, its old address in each language keeps working with a permanent redirect.
  • Children move with their parent, language by language. Publishing a page in a language saves its children again in that language, so their paths follow (resaveChildren in src/collections/Pages/hooks, in place of the nested-docs plugin's own, see src/plugins/pageTree.ts). Only children with a slug of their own in that language are saved, from what that language has; the others keep falling back to the default language, address included, and get a slug from their own title when they are translated.

Fallback #

The site never shows an empty page because a translation is missing:

  • An empty text field shows the default language's text.
  • A page's blocks are the default language's until the language has blocks of its own. From then on each language owns its layout, and editors keep the copies in step with the block sync panel (see Blocks in other languages).
  • Interface texts (buttons, messages, labels) come from src/messages/<code>.json. A language without its own file uses the default language's (and English's, where the default language has no file either), and editors can override any text per language in Microcopy.

In the admin, each language shows only its own content: an empty field there is one that falls back on the site.

These guides ship with Tolk Starter 0.8.0: buyers get the same pages in their repository, next to the code they describe.