Skip to content

Localize the remaining hard-coded Admin UI strings, with English fallback - #1675

Open
ganlub wants to merge 12 commits into
Thinkmill:mainfrom
ganlub:l10n-hardcoded-strings
Open

ganlub wants to merge 12 commits into
Thinkmill:mainfrom
ganlub:l10n-hardcoded-strings

Conversation

@ganlub

@ganlub ganlub commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Closes #1578. Refs #401.

locale only 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 any locale until someone translates it. With en-US nothing 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:

  • Places that now use one of the existing 27 keys show that key's existing translation. Examples are the singleton Save/Create button, the blocks field's Add button, the dashboard's Add buttons, the Markdoc component Edit button, Cancel in the delete and cloud image dialogs, the Dashboard button on the collection error state, "Branch name" in the "New branch…" dialog and the delete branch dialog title.
  • The "Some characters are not allowed" branch name error formats its list with the UI locale, so the "and" in it follows the locale.

Falling back to English

LocalizedStringDictionary throws (Could not find intl message … in ca-ES locale) when a key is missing from a locale that exists. Adding a key to en-US alone would therefore break every other locale. Both generators (packages/keystatic/scripts/l10n.ts and design-system/pkg/build-l10n.mts) now emit the en-US strings once and spread them under each locale's own strings:

"ca-ES": { ...defaultLocaleStrings, "add": `Afegeix`, /* … */ },

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.ts files now list the en-US keys, so stringFormatter.format('typo') is a type error instead of a runtime crash.

How strings are localized

  • Components use the existing useLocalizedStringFormatter(l10nMessages) / useLocalizedString().
  • Sentences with a link or <code> inside (e.g. "There aren't any entries yet. {createLink} to see it here.") are a single message, and formatWithElements puts the element in.
  • Elements created outside a component (the module-level toolbar buttons, a few tooltips) use a small <LocalizedText id="…" />.
  • Module-level tables (inline marks, alignment, table cell actions, entry actions) store keys and format them at render. The Markdoc schema's insert menu items store { key, args }; custom components keep their own label.
  • Counts use plurals, e.g. {count, plural, =1 {{count} entry} other {{count} entries}}. The English messages use =1 rather than one because the fallback is formatted with the UI locale's plural rules: with one, fr-FR would show "0 entry" and ru-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.
  • Field validators (validateText, validateNumber, …) take an optional formatter. The field inputs pass the UI's formatter. The validate/reader path, which also runs in the node/worker/react-server builds, uses defaultStringFormatter. That formatter is built from a generated default-locale.js containing only en-US, so those builds don't pull in every locale. They do now include the en-US strings and @internationalized/string. I checked that the built node, worker and react-server bundles contain no other locale.
  • The Markdoc editor placeholder is resolved from the view's props, in the same way the editor already passes config. Cloud image uploads started from drag and drop use config.locale.
  • The "characters not allowed" branch name error uses the UI locale for Intl.ListFormat instead of a hard-coded en-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
  • App shell and dashboard: theme menu (Light/Dark/System, "theme"), user menu (Log out, Account, Image library, "User menu", Sign into Cloud), git menu (Github repo, Pull Request #n, View fork, Repository, "git actions"), delete branch dialog, "Open app navigation", change badges and their screen reader text (plural), "Changed", Branch not found / Failed to load shell, "Git repo not initialised", dashboard entry and change counts (plural), "Content", "Hello, {name}!", Manage Account, "Pull request #n".
  • Collection and entry pages: search button, loading/empty/no results states, the Status/Slug/Name columns and status cell text, the entry and singleton action menus (Reset changes / Reset, Delete entry…, Copy entry, Paste entry, Duplicate entry…, Preview, View on GitHub), "Saving changes", "Unsaved", the singleton Save/Create button, "Updating/Loading {name}", the delete and duplicate dialogs, the toasts (Entry created/pasted, Undo, clipboard errors), "Entry not found.", "Loading Item", "Creating entry", the restored draft toast, the "New branch…" dialog (reasons, "Create branch and save", "Creating Branch", branch name errors), update errors (GitHub App can't commit, Failed to update), the fork dialog.
  • Sign-in and GitHub setup: Log in with GitHub / Keystatic Cloud, cloud auth callback states, "Not found" pages, setup, install app, repo not found and app created screens.
  • Field inputs and validation: text/slug/number/integer/date/datetime/url/relationship/multi-relationship/path reference/image/file required and range messages, array and blocks (Add, Edit {name}, Add {name}, Edit item, Add item, Done, Item n, Empty list, min/max items plural), image and file inputs (Choose file, Remove, Download, Filename), slug (default "Slug" label, Regenerate), multi-relationship (All selected, No more items…, No items selected…, Remove), cloud image field (Image URL, Alt text, help text, checking, awaiting preview).
  • Document editor: toolbar (Paragraph, Heading n, Text block, inline marks, Collapse/Expand, Insert, alignment, lists, Quote, Divider, Code block, Link, Image, Table, Layouts), "/" insert menu, placeholder, popovers (Remove, Unlink, Header row, Options, table row/column actions and selection labels, "Language"), image, link, component block and custom attribute dialogs, "Contains invalid fields. Please edit."
  • Markdoc/MDX editor: toolbar and its aria-labels, inline marks, lists, insert menu labels and descriptions, "Insert menu", "No results…", placeholder, popovers (Edit, Remove, Header row, Unlink, "Code block language", cell options and actions), image and link dialogs, custom component Edit/Insert/"Edit {name}".
  • Keystatic Cloud images: image dialog and preview, dimensions (Width, Height, Constrain proportions, Revert to original), upload button, upload toasts and errors.
  • @keystar/ui: SplitView resize handle ("Resize", which had a FIXME: localize), and the non-Mac modifier labels in Kbd (Alt, Ctrl, Shift).

Left out on purpose

  • Labels of built-in field definitions: the default Items (array), Kind (blocks), Empty and Ignored labels; the default image Alt text field (with its description) and Title field in fields.document/fields.markdoc; the URL/Alt text/Width/Height fields 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 default Slug label is localized in the input, since it's only a fallback there.
  • Content data errors: FieldDataError messages 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.
  • Commit messages (Update {path}, Delete {path}), because they're written to the repository.
  • "Plain text" in the code block language picker: it's an entry in the language list and is used as a lookup key there. Like the language names, it stays as is.
  • Developer diagnostics and other non-UI text: "The block … no longer exists. Props: …", 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.
  • Code that isn't rendered: app/shell/BatchCommits.tsx and app/dashboard/content.ts aren't imported anywhere.

Where the same text appears with different capitalization or punctuation ("Pull Request #" / "Pull request #", "Bullet List" / "Bullet list", the ... / … placeholders, the regenerate aria-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's aria-label, which says "Divider" today and still does.

Tests

  • packages/keystatic/src/app/l10n/l10n.test.ts: every generated locale has every en-US key. 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. Every en-US message without arguments compiles back to exactly its source text (ICU escaping). The count messages match what pluralize printed before.
  • design-system/pkg/test/l10n.test.ts: every generated @keystar/ui locale has every en-US key.
  • pnpm check:format, check:lint, check:types, check:packages, test:unit and build:packages pass locally.

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.
@ganlub
ganlub requested a review from emmatown as a code owner November 18, 2026 15:32
@changeset-bot

changeset-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fc6d03b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@keystar/ui Patch
@keystatic/core Patch

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

locale only covers 27 strings, so a translated UI comes out half-English

1 participant