8000 fix(i18n): workbench preview renders the target locale on Sylius hosts by Klehm · Pull Request #61 · Klehm/content-blocks-project · GitHub
[go: up one dir, main page]

Skip to content

fix(i18n): workbench preview renders the target locale on Sylius hosts - #61

Merged
Klehm merged 1 commit into
masterfrom
fix/i18n-workbench-preview-locale
Sep 29, 2026
Merged

Klehm merged 1 commit into
masterfrom
fix/i18n-workbench-preview-locale

Conversation

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

Problem

On a Sylius host (Bocklip), the translation workbench had two problems:

  1. The preview stayed in the source language. After "Translate the page", the page reloaded but the preview still showed the French text. A translation appeared only after you edited its field.
  2. No sign that a run was in progress. "Translate the page" showed a toast that disappears after 1.8 s, while a provider call can take much longer.

Cause of (1)

PreviewLocaleListener (kernel.request, priority 15) sets the request locale to the workbench locale. Sylius's RequestLocaleSetter (priority 4) runs after it and sets the channel locale back, so the whole preview page renders in the source language. Editing a field refreshes only that block, through the render route that takes the locale as an explicit parameter, which is why an edited field showed its translation.

Changes

  • PreviewLocaleListener also stores the locale in a request attribute (PreviewLocaleListener::ATTRIBUTE). RequestRenderLocaleResolver reads that attribute on the main request before the request locale, so sub-requests are covered too. The host's own strings (header, menu) stay in the host's locale; only the content follows the workbench. The guards (cb_preview=1 plus the session marker) are unchanged.
  • "Translate the page" and each field's ⚡ button show a spinner and are disabled (aria-busy) until the provider answers. The page button stays busy until the page reloads, and becomes clickable again if the call fails.
  • The cause is explained in docs/internals/i18n.md#the-preview-pane; the i18n CHANGELOG has an entry under Unreleased.

Tests

  • PHPUnit (i18n): the listener sets the attribute, and the resolver keeps the preview locale when the host resets the request locale, including in a sub-request. 184 tests pass.
  • Vitest: both buttons are busy while their call is pending, a second click does nothing, and the button is enabled again after a failure. 30 tests pass.
  • Playwright translation-workbench and import-export-i18n: 9 specs pass. PHPStan and php-cs-fixer are clean.

The main sandbox does not use Sylius core, so no e2e test covers the Sylius case; the resolver's unit test covers it.

🤖 Generated with Claude Code

Sylius's RequestLocaleSetter (kernel.request, priority 4) runs after
PreviewLocaleListener and puts the channel locale back, so the whole preview
pane rendered the source text; only a just-edited block, rendered through the
route that passes the locale explicitly, showed its translation.

The listener now also pins the locale on the main request, and
RequestRenderLocaleResolver reads it before the request locale.

The page and field machine-translation buttons show a spinner and are
disabled while the provider runs, so a run cannot be started twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Klehm
Klehm merged commit a8f777c into master Sep 29, 2026
36 checks passed
@Klehm
Klehm deleted the fix/i18n-workbench-preview-locale branch September 29, 2026 08:28
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