Repository navigation
Conversation
Generated locale modules now spread the en-US strings under each locale's own strings, so a locale that doesn't have a key shows the English text instead of throwing. The generated types also list the en-US keys, so unknown keys are type errors.
…nt children in Text Plural messages now use =1 instead of one, so the English fallback matches pluralize in every locale (e.g. not "0 entry" in fr-FR or "21 entry" in ru-RU). Tooltips and buttons only wrap string children in Text, so messages rendered with LocalizedText are wrapped explicitly.
🦋 Changeset detectedLatest commit: fc6d03b The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 branch has not been deployed
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.
Closes #1578. Refs #401.
localeonly covered 27 keys. Everything else in the Admin UI was English written straight into the components, so a translated UI came out half English. This PR moves the remaining user-facing strings into the localization files and makes missing translations fall back to English. Translations can then be added a locale at a time.No translations are added. All new keys exist only in
en-US, so new text keeps showing in English under anylocaleuntil someone translates it. Withen-USnothing changes: every new message produces the same English text as the code it replaces.Two things do change under a non-English
locale, both on purpose:Falling back to English
LocalizedStringDictionarythrows (Could not find intl message … in ca-ES locale) when a key is missing from a locale that exists. Adding a key toen-USalone would therefore break every other locale. Both generators (packages/keystatic/scripts/l10n.tsanddesign-system/pkg/build-l10n.mts) now emit theen-USstrings once and spread them under each locale's own strings:This works the same way for every locale, in both packages, and doesn't duplicate any strings. A locale with no file at all already fell back to
en-US.The generated
.d.tsfiles now list theen-USkeys, sostringFormatter.format('typo')is a type error instead of a runtime crash.How strings are localized
useLocalizedStringFormatter(l10nMessages)/useLocalizedString().<code>inside (e.g. "There aren't any entries yet. {createLink} to see it here.") are a single message, andformatWithElementsputs the element in.<LocalizedText id="…" />.{ key, args }; custom components keep their ownlabel.{count, plural, =1 {{count} entry} other {{count} entries}}. The English messages use=1rather thanonebecause the fallback is formatted with the UI locale's plural rules: withone,fr-FRwould show "0 entry" andru-RU"21 entry". They also use{count}rather than#so that numbers aren't grouped ("1000 entries", as today). Translations can use whatever categories their language needs.validateText,validateNumber, …) take an optional formatter. The field inputs pass the UI's formatter. Thevalidate/reader path, which also runs in the node/worker/react-server builds, usesdefaultStringFormatter. That formatter is built from a generateddefault-locale.jscontaining onlyen-US, so those builds don't pull in every locale. They do now include theen-USstrings and@internationalized/string. I checked that the built node, worker and react-server bundles contain no other locale.config. Cloud image uploads started from drag and drop useconfig.locale.Intl.ListFormatinstead of a hard-codeden-US.Inventory
256 new keys in
@keystatic/core(27 → 283) and 4 in@keystar/ui. The commits are split by area.Full list by area
SplitViewresize handle ("Resize", which had aFIXME: localize), and the non-Mac modifier labels inKbd(Alt, Ctrl, Shift).Left out on purpose
Items(array),Kind(blocks),EmptyandIgnoredlabels; the default imageAlt textfield (with its description) andTitlefield infields.document/fields.markdoc; theURL/Alt text/Width/Heightfields in the cloud image schema. These are created when the config is evaluated, before any locale is known, and are rendered like user-defined field labels. Localizing them would need localized field labels, which is a separate change. The slug field's defaultSluglabel is localized in the input, since it's only a fallback there.FieldDataErrormessages from parsing entries ("Must be a string", "Must be an object",parse-props,validateArrayLength,assertRequired) and the "Field validation failed:" wrapper. They describe invalid files, are mainly for developers, and are also thrown by the reader. The validation messages shown under fields are localized.Update {path},Delete {path}), because they're written to the repository.Missing image {filename}(inserted into the document content), console messages, thrown invariant and config errors, the insert menu search keywords (ordered list,unordered list, which aren't displayed), environment variable names and brand names.app/shell/BatchCommits.tsxandapp/dashboard/content.tsaren't imported anywhere.Where the same text appears with different capitalization or punctuation ("Pull Request #" / "Pull request #", "Bullet List" / "Bullet list", the
.../…placeholders, theregeneratearia-label next to the "Regenerate" button, "Image library" / "Image Library"), I kept separate keys so the English output is byte-for-byte the same. They can be merged later if you'd rather normalize the copy. The same goes for the Markdoc link button'saria-label, which says "Divider" today and still does.Tests
packages/keystatic/src/app/l10n/l10n.test.ts: every generated locale has everyen-USkey. A locale that lacks a key (e.g.ca-ES) formats it as the English text, for counts 0, 1, 2, 5, 21, 101 and 1000. Everyen-USmessage without arguments compiles back to exactly its source text (ICU escaping). The count messages match whatpluralizeprinted before.design-system/pkg/test/l10n.test.ts: every generated@keystar/uilocale has everyen-USkey.pnpm check:format,check:lint,check:types,check:packages,test:unitandbuild:packagespass locally.