Repository navigation
feat(i18n): publish one language, and carry translations through templates and the clipboard - #63
Merged
Merged
Conversation
…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>
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.
Why
Two gaps from the roadmap, and one bug found while looking at them:
ContentArea::hasUnpublishedChanges()only looks at sections, columns and blocks, and cannot see the translation tables.PublishContexthas existed since 1.0, but nothing passed it.What changes
Core (
klehm/content-blocks), additiveUnpublishedChangesProviderInterface(optional, autoconfigured): a bundle that keeps a draft of its own beside the area reports it.UnpublishedChangesreads the area's own draft first and asks the providers only if the area is clean. The shell, the launcher badge and every endpoint answeringhasUnpublishedChangesuse it, and templates call the new Twig functioncb_has_unpublished_changes(area).ContentArea::hasUnpublishedChanges()itself is unchanged.SnapshotExtensionInterface(optional, autoconfigured): does for section templates and the clipboard whatContentAreaTransferExtensionInterfacedoes for export. The payload goes underextensions.<key>of the snapshot. The two serializers, which are frozen, are unchanged, and older templates and clipboard entries read as before.c{j}for a column,c{j}.b{k}for a block,bfor a block copied alone. On restore, the mapping steps past what the instantiator skipped (a malformed column, a block whose type is gone).i18n (
klehm/content-blocks-i18n)TranslationDraftsreports 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.PublishContext::withLocales(), through two new routes:content_blocks_i18n_area_publishandcontent_blocks_i18n_area_discard.409 source_unpublishedwhile 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.aria-disabled rather thandisabled, so it can still be hovered and its title says why: nothing to publish, or the page has a draft.TranslationSnapshotExtensioncarries translations through templates and the clipboard, tab titles included.items[#1].label): a pasted block is replayed through its form, which gives its collection entries new_ids, soitems[9f2c].labelwould address nothing in the copy. New helpersFieldPath::toPositional()/fromPositional()convert both ways.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
scripts/bc-check/run.shreports no backwards-incompatible change.builder/shell.html.twigorlauncher.html.twigkeeps the old reading of the Publish button until it switches tocb_has_unpublished_changes(area). This is in the core CHANGELOG.klehm/content-blocks: ^1.0, which avoids touching the fivecomposer.lockfiles. 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
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.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.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.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.FieldPathpositional 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.Vitest, i18n (39): a save turns the button on; publishing saves pending edits first;
source_unpublishedblocks 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:/en/page/{id}only;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