Add content internationalization#1553
Conversation
🦋 Changeset detectedLatest commit: cd7e012 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This would be amazing! ⬆️ |
|
Nice work so far. Could you also extend this to support Astro's |
Thanks! Before I look into it — could you share what you're after with this? Just want to understand the use case. The reason I ask: Astro's The main case I can think of is an existing repo whose default content already sits at the collection root, where you'd want to add translations without moving those files into Then switch the collection There's also a catch with collections that use the ** path wildcard (it lets a collection store entries across nested subfolders, with slugs like Removing the folder for the default language would put the English entries directly under Is it the existing-repo case, or something else you're running into? |
|
@timmy-why thanks for the detailed breakdown! The main driver here isn't just migrating existing repos, but supporting a standard Astro pattern. For Astro sites configured with Supporting this structure: ...is crucial for native Astro/Starlight compatibility, even though I understand the |
66e568a to
cd7e012
Compare
|
@maxmorozoff you were right — Starlight deriving the locale from the directory, and Markdown in What's in
Defaults to The Trying itPreview packages are published per commit:
Keystatic config for a Starlight root locale (Starlight on English resolves to I verified it on two throwaway Astro 7 projects — a Starlight site with a root locale and a plain blog covering both your cases ( |
Hey! 👋 This PR adds content internationalization to Keystatic — here's the gist.
Adds content i18n so you can author a collection or singleton in multiple languages.
Set
i18non the config, mark an entrylocalized, and drop a{locale}token into itspath:Each language gets its own file/folder on disk (
content/posts/en/…,content/posts/pl/…), but the entry still shows up once in the navigation — a language switcher at the top of the sidebar decides which one you're editing. Entries without a{locale}token stay shared across all languages. Note this localizes your content, which is separate from the existinglocaleoption that just sets the Admin UI language.Since the token is just a folder in the path prefix, you can turn this on for an existing multi-language project without moving any files.
The Reader API reads one language at a time —
createReader/createGitHubReadernow take a{ locale }option:Config is validated up front, so a
localizedentry without a{locale}token (or vice versa), a missingi18n, or a baddefaultLocaleall fail with a clear error instead of breaking later.Scoped to
@keystatic/core. Docs are in the new Internationalization page, and there are tests for the path/token handling and locale-scoped reads.Demo
Here's the flow end to end — opening a singleton and a collection while switching languages: for a singleton the form fields below swap to the selected locale's values automatically, and for a collection the list filters down to that language's entries:
i18n.showcase.mov
And the same language switcher above the navigation with GitHub mode, so you can see it isn't tied to local mode: