Skip to content

Post Translation: New plugin for translating post/page content via GlotPress#602

Open
dd32 wants to merge 15 commits intoWordPress:trunkfrom
dd32:create/claude/post-translation-plugin
Open

Post Translation: New plugin for translating post/page content via GlotPress#602
dd32 wants to merge 15 commits intoWordPress:trunkfrom
dd32:create/claude/post-translation-plugin

Conversation

@dd32
Copy link
Copy Markdown
Member

@dd32 dd32 commented Apr 13, 2026

Summary

  • New wporg-post-translation plugin that translates WordPress post/page content through GlotPress
  • Block parser system extracts translatable strings from Gutenberg blocks (paragraph, heading, image, list, quote, button, shortcode) with a fallback parser for unknown blocks
  • Editor sidebar panel with a toggle to enable translation per-post
  • Admin hook schedules GlotPress import when a translated post is saved
  • Frontend filters (the_content, the_title, render_block) apply translations with transient caching using a compound invalidation key (posts + GlotPress last_changed)
  • Adds $found parameter to GlotPress Translate Bridge for distinguishing untranslated strings
  • gettext filter hooks for future live translator UI integration (informed by the add/translator branch)
  • PHPUnit test suite: 29 unit/integration tests + 6 end-to-end tests through GlotPress
  • wp-env local development environment with GlotPress, in environments/post-translation/

Context

Currently, translatable page content on WordPress.org lives in theme template files (wporg-main-2022) so it can be wrapped in translation functions. This means content changes require theme code changes rather than using the WordPress editor. This plugin enables page content to live in the database as normal posts/pages while still being translatable through GlotPress.

Informed by prior work on the feature/post-translation and add/translator branches, but is a fresh implementation.

Test plan

  • cd environments && npm run post-translation:env start
  • Verify editor sidebar toggle appears for posts/pages
  • Enable translation on a post, save, verify strings appear in GlotPress project
  • Add a translation in GlotPress, verify it renders on the frontend for that locale
  • Run tests: npm run post-translation:env -- run cli --env-cwd=wp-content/plugins/wporg-post-translation phpunit

🤖 Generated with Claude Code

dd32 and others added 3 commits April 13, 2026 16:20
New plugin that translates WordPress post/page content via GlotPress.
Extracts translatable strings from block content, imports them into
GlotPress projects, and applies translations on the frontend.

- Block parser system with specialized parsers for core blocks
  (paragraph, heading, image, list, quote, button, shortcode) and
  a BasicText fallback for unknown blocks
- Editor sidebar panel with toggle to enable translation per-post
- Admin hook schedules GlotPress import on post save
- Frontend filters (the_content, the_title, render_block) apply
  translations with transient caching using compound invalidation key
- Adds $found parameter to GlotPress Translate Bridge for distinguishing
  untranslated strings from identity translations
- PHPUnit test suite (29 tests) with wp-env environment
- gettext filter hooks for future live translator UI integration

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add GlotPress plugin to the wp-env environment with lifecycle
  scripts that set up permalinks and install GlotPress DB tables
- Fix wp-env plugin paths (relative to environments/ working dir)
- Update bootstrap to load GlotPress with case-insensitive path
  lookup and install its schema for the test database
- Add 6 end-to-end tests covering the full translation pipeline:
  import strings into GlotPress, add translations, verify frontend
  serves translated content, verify multi-post string preservation,
  verify auto-creation of projects with translation sets

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The wp-env container ships PHPUnit 10.5 which is incompatible with the
bundled WordPress test suite (uses removed parseTestMethodAnnotations).
Add a conditional step to downgrade to PHPUnit 9 and use the vendored
binary instead of the system one. Only applies to entries that set
phpunit-bin in the matrix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props dd32.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

dd32 and others added 12 commits April 13, 2026 17:20
- Fix all PHPCS errors across plugin files (multi-line function calls,
  Yoda conditions, alignment, trait/class-per-file ignores for
  DOMDocument properties and related types)
- Add PHPDoc for $found parameter on GlotPress Translate Bridge
  translate() and translate_plural() methods
- Fix wp-env lifecycle script to use wp-env run cli (runs in container,
  not on host)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Use after-start.sh script for wp-env lifecycle (matching
  plugin-directory pattern) instead of inline wp-env commands
  that fail during the start process
- Exclude */build/* from PHPCS - wp-scripts generated asset files
  are not hand-written PHP

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add missing parameter types to PHPDoc and visibility declarations
to translate() and translate_plural() methods.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…nment.

- Map mocks/mu-plugins for the dev login button on the login screen
- Add wporg-main theme and wporg-parent-2021 parent theme
- Activate wporg-main in after-start script

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
switch_to_blog() and restore_current_blog() do not exist on single-site
WordPress installs. Guard all calls with is_multisite() checks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ctory.

The mocks/mu-plugins directory includes a loader that requires
wporg-mu-plugins which is not available in this environment.
Map just the dev-login file instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Installs Spanish language pack and switches the site language so
the frontend always attempts to translate post content.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
In cron context, get_permalink() resolves to the wrong URL because
the site URL is not available from the request. Pass the permalink
as a cron argument so it uses the correct URL from save time.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Rename GlotPress project hierarchy from disabled/posttranslation to
  post-content (top-level "Post Content" project with site name as
  child project)
- Importer auto-creates parent project if it does not exist
- Child projects use the site name from get_bloginfo() instead of slug
- After-start script creates parent project with Spanish translation
  set, sample page with various block types and translation enabled,
  and triggers cron to import strings into GlotPress
- Update tests for new project path

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
`wp post-translation import` finds all published posts with translation
enabled and imports their strings into GlotPress. Operates per-site
(use --url= on multisite). Supports --post_id, --post_type, and
--dry-run flags.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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