Skip to content

fix(editor): translate the patterns count and fall back for new editor strings - #25848

Open
dcalhoun wants to merge 6 commits into
trunkfrom
fix/gutenbergkit-localization-fallback
Open

fix(editor): translate the patterns count and fall back for new editor strings#25848
dcalhoun wants to merge 6 commits into
trunkfrom
fix/gutenbergkit-localization-fallback

Conversation

@dcalhoun

@dcalhoun dcalhoun commented Jul 28, 2026

Copy link
Copy Markdown
Member

Description

Adopts GutenbergKit#569, which localizes the block inserter's pattern count and lets host apps fall back to the editor's own strings for keys they do not translate.

Two changes here:

Translate patternsCount. GutenbergKit#569 adds EditorLocalizableString.patternsCount(Int) for a string that previously rendered as hardcoded English. Singular and plural are split so each reads naturally rather than forcing "1 pattern(s)".

Decline unhandled keys. getLocalizedString(for:) switched over the enum exhaustively, so every string the editor added broke this build until someone wrote a translation — and the break surfaced on the dependency bump, not when the string was added. Unhandled keys now return nil, and the editor supplies its own string:

@unknown default:
    nil

New editor strings render in English until translated, instead of failing to compile. @unknown default rather than a plain default because this switch currently covers every case, and a plain one warns "default will never be executed."

EditorLocalization.localize now returns String?, so getLocalizedString(for:) and EditorLocalizableString.localized return optionals to match. The install site in PostGBKEditorViewController is unchanged — { $0.localized } already fits the new closure type.

Note that @unknown default covers only keys added by a future GutenbergKit. Skipping a case that exists today is still a compile error, so this cannot silently drop a translation we meant to write.

Note

Modules/Package.swift pins a GutenbergKit revision while that PR is open. The TODO there marks restoring a version pin once it ships. This PR should not merge before GutenbergKit#569.

Testing instructions

The pattern count is the visible change:

  1. Open the editor and tap + for the block inserter.
  2. Switch to the Patterns tab on a site that has patterns.
  3. Confirm section headers show a localized count, and that a category with exactly one pattern reads "1 pattern" rather than "1 patterns".

To verify the fallback, which has no visible effect until GutenbergKit adds a string:

  1. Comment out a case in getLocalizedString(for:).patterns or .search render unconditionally and are easy to spot. Return nil for it instead, since removing the case outright is a compile error.
  2. Run the app and open the block inserter.
  3. Confirm the string renders in English rather than crashing or rendering empty.
  4. Confirm the console shows [GutenbergKit:localization] Missing host translation for …, or filter Console.app on subsystem GutenbergKit. Each key reports once per launch, so scrolling a list will not repeat it.
  5. Restore the case.

Nothing reports with every case handled, which is the expected state on trunk.

@wpmobilebot

Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@wpmobilebot

wpmobilebot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number33532
VersionPR #25848
Bundle IDorg.wordpress.alpha
Commit1311278
Installation URL76l3qa5e29220
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number33532
VersionPR #25848
Bundle IDcom.jetpack.alpha
Commit1311278
Installation URL66jtjo56q386g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@dcalhoun
dcalhoun marked this pull request as ready for review July 28, 2026 19:01
@dcalhoun
dcalhoun requested a review from crazytonyli July 28, 2026 19:01
dcalhoun and others added 6 commits July 29, 2026 15:18
GutenbergKit#569 adds `EditorLocalizableString.patternsCount(Int)`, which is
source-breaking for hosts that switch over the enum exhaustively. Track the
PR build so the companion changes can land and be tested together.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
GutenbergKit#569 adds `patternsCount(Int)`, which previously rendered as a
hardcoded English string. Translate it, splitting singular and plural so
each reads naturally.

Also delegate unhandled keys to `EditorLocalization.defaultLocalize(_:)`.
The switch was exhaustive, so every string the editor added broke this build
until someone wrote a translation — and the break surfaced on the dependency
bump, not when the string was added. New keys now render in English until
translated.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A plain `default` warns "default will never be executed" because this switch
covers every case the pinned GutenbergKit defines. `@unknown default`
compiles clean and behaves the same once the editor adds a string.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
GutenbergKit#569 changed `EditorLocalization.localize` to return `String?`.
Hosts now decline a key by returning `nil` instead of calling a public
`defaultLocalize`, so the editor supplies the string and reports the gap.

`getLocalizedString(for:)` and `EditorLocalizableString.localized` return
`String?`, and the fallback case yields `nil`. The install site in
PostGBKEditorViewController needs no change: `{ $0.localized }` already
matches the new closure type.

Keeps the `@unknown default` from 88bbcf4. It stays reachable only for
keys a future GutenbergKit adds; every case defined today is still handled
explicitly, so the pattern count keeps its own translation rather than
falling through.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dcalhoun
dcalhoun force-pushed the fix/gutenbergkit-localization-fallback branch from 786e07d to 1311278 Compare July 29, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Gutenberg Editing and display of Gutenberg blocks. [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants