8000 feat(i18n): publish one language, and carry translations through templates and the clipboard by Klehm · Pull Request #63 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

Skip to content

feat(i18n): publish one language, and carry translations through templates and the clipboard - #63

Merged
Klehm merged 1 commit into
masterfrom
feat/i18n-publish-and-carry
Sep 29, 2026
Merged

Klehm merged 1 commit into
masterfrom
feat/i18n-publish-and-carry

Conversation

@Klehm
@Klehm Klehm commented Sep 29, 2026
Copy link
Copy Markdown
Owner

Why

Two gaps from the roadmap, and one bug found while looking at them:

  • Bug: on a page that is already published, translating a field in the workbench left the builder's Publish button disabled. The translation could not go live unless the page was edited too. The cause is that ContentArea::hasUnpublishedChanges() only looks at sections, columns and blocks, and cannot see the translation tables.
  • No per-language publishing: PublishContext has existed since 1.0, but nothing passed it.
  • Section templates and the clipboard dropped translations: a translated section saved to the library, or copied and pasted, arrived untranslated.

What changes

Core (klehm/content-blocks), additive

  • UnpublishedChangesProviderInterface (optional, autoconfigured): a bundle that keeps a draft of its own beside the area reports it. UnpublishedChanges reads the area's own draft first and asks the providers only if the area is clean. The shell, the launcher badge and every endpoint answering hasUnpublishedChanges use it, and templates call the new Twig function cb_has_unpublished_changes(area). ContentArea::hasUnpublishedChanges() itself is unchanged.
  • SnapshotExtensionInterface (optional, autoconfigured): does for section templates and the clipboard what ContentAreaTransferExtensionInterface does for export. The payload goes under extensions.<key> of the snapshot. The two serializers, which are frozen, are unchanged, and older templates and clipboard entries read as before.
    • Refs are positions in the default serializer's walk: c{j} for a column, c{j}.b{k} for a block, b for a block copied alone. On restore, the mapping steps past what the instantiator skipped (a malformed column, a block whose type is gone).
    • Restore runs after the copies are flushed, because a row beside a block needs its id. It flushes again only if an extension actually restored something.

i18n (klehm/content-blocks-i18n)

  • TranslationDrafts reports which languages have a pending translation. It feeds the builder's Publish button, and the new Publish EN button in the workbench. A draft identical to what is live does not count.
  • Workbench: Publish EN / Discard changes. They call the publisher with PublishContext::withLocales(), through two new routes: content_blocks_i18n_area_publish and content_blocks_i18n_area_discard.
    • Refused with 409 source_unpublished while the page has unpublished changes of its own. Publish and discard always act on the page's draft too, so the call would put an editor's unfinished work live, or throw it away. This keeps the invariant that a language is never pushed ahead of its source.
    • When off, the button is aria-disabled rather than disabled, so it can still be hovered and its title says why: nothing to publish, or the page has a draft.
    • Publish events fire as for the builder, so a listener can refuse.
    • Before publishing, the workbench saves what is still being typed. Discard asks for confirmation, then reloads the page.
  • TranslationSnapshotExtension carries translations through templates and the clipboard, tab titles included.
    • Collection paths are stored by position (items[#1].label): a pasted block is replayed through its form, which gives its collection entries new _ids, so items[9f2c].label would address nothing in the copy. New helpers FieldPath::toPositional() / fromPositional() convert both ways.
    • The clipboard lives in the browser's storage, so the fragment is untrusted. Every value goes through TranslationWriter::restore(): the same allow-list, path, length and media checks as a typed value, with the captured digest carried so an outdated translation stays outdated.

Compatibility

  • No migration, and scripts/bc-check/run.sh reports no backwards-incompatible change.
  • A host that copied builder/shell.html.twig or launcher.html.twig keeps the old reading of the Publish button until it switches to cb_has_unpublished_changes(area). This is in the core CHANGELOG.
  • Dependency floor: i18n now uses two core 1.2 interfaces but keeps klehm/content-blocks: ^1.0, which avoids touching the five composer.lock files. The two classes implementing those interfaces are registered only when the interfaces exist, so on an older core the package still boots, without these features. The three packages should be released together as 1.2.0.

Docs

  • Guide translation.md: new section Draft, published, and publishing one language, and the "templates and clipboard don't carry translations" limitation removed. Same edit in the i18n README.
  • Internals: i18n.md (#publishing-one-language, #translations-in-templates-and-the-clipboard), publishing.md (#drafts-kept-beside-the-area), section-templates.md (#rows-kept-beside-a-block).
  • backward-compatibility.md: the 2 new interfaces, the 2 routes with their payload, the Twig function.
  • ROADMAP: 3 items ticked. Per-language publishing from the builder stays open, on demand.
  • CHANGELOGs for core and i18n, and CLAUDE.md.

Tests

  • PHPUnit, core (1071):

    • UnpublishedChanges: providers are asked only when the area is clean.
    • AreaController::state() reports a provider's draft.
    • SnapshotExtensions: refs follow live order, deleted entities are skipped, restore steps past skipped blocks and malformed columns, no key means nothing is called.
    • The clipboard and template controllers capture and hand the copies over after the flush.
  • PHPUnit, i18n (208):

    • TranslationDrafts, including a draft equal to what is live.
    • LocalePublishController: one language only, refusal while the page has a draft, a refusing listener, the guards.
    • FieldPath positional round trip, including nested collections.
    • TranslationWriter::restore(): digests carried, gates applied, media checked.
    • TranslationSnapshotExtension: round trip across new entry ids, a forged fragment rejected, tab titles.
    • Workbench template: the button's three states and their titles.
  • Vitest, i18n (39): a save turns the button on; publishing saves pending edits first; source_unpublished blocks the button and says why; a click on the off button sends nothing; discard asks for confirmation.

  • Playwright, new spec i18n-publish-and-carry.spec.js:

    • a translation of a published page lights the builder's Publish, then is published from the workbench and served on /en/page/{id} only;
    • the workbench refuses while the page has a draft, and the tooltip says why;
    • a section saved as a template keeps its translations;
    • a pasted section keeps them too.

    Main suite 203 passed, Encore 7 passed.

  • PHPStan, php-cs-fixer and the comment budget are clean. The Sylius and Encore sandboxes compile.

🤖 Generated with Claude Code

…lates and the clipboard

A translation typed on an already-published page left the builder's Publish
button disabled: ContentArea::hasUnpublishedChanges() cannot see the
translation table. The core now also asks UnpublishedChangesProviderInterface
services (UnpublishedChanges, Twig cb_has_unpublished_changes()), and the
i18n package answers through TranslationDrafts.

The workbench gets Publish EN / Discard changes for its own language
(PublishContext::withLocales()), refused with 409 source_unpublished while
the page has a draft of its own, which the call would put live. Off, the
button stays hoverable (aria-disabled) so its title says why.

Section templates and the clipboard carry translations through a new core
SnapshotExtensionInterface, under extensions.<key> of the snapshot. Paths are
kept by entry position, since a paste re-mints collection entry ids, and
restored through TranslationWriter::restore() with digests carried.

The two i18n classes implementing the new core seams are registered only
when the interfaces exist, so the package still boots on an older core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Klehm
Klehm merged commit 02fa418 into master Sep 29, 2026
36 checks passed
@Klehm
Klehm deleted the feat/i18n-publish-and-carry branch September 29, 2026 09:22
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.

1 participant

0