Add content internationalization#1553
Open
timmy-why wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: 1d161f7 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 |
Contributor
|
This would be amazing! ⬆️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: