Skip to content

Keep translation catalogs stable across code-only changes - #148

Merged
erseco merged 1 commit into
mainfrom
feature/pot-file-references
Sep 26, 2026
Merged

erseco merged 1 commit into
mainfrom
feature/pot-file-references

Conversation

@erseco

@erseco erseco commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

Problem

wp i18n make-pot writes #: file:line references. Any change that moves a translatable string to a different line rewrites the POT and all ten PO files. CI's make check-translations then requires committing that churn together with the code. #124 and #125 each carry hundreds of reference-only catalog lines for this reason, although neither changes a single msgid.

Change

  • New bin/pot-strip-line-numbers.php, run by composer make-translations and check-untranslated right after pot-remove-ctime. It reduces each #: line in the POT to its file names: it drops the line numbers and removes repeated files. wp i18n update-po then carries those references into the PO files.
  • File names are kept on purpose. wp i18n make-json uses them to map JavaScript strings to their scripts, so --no-location would have broken the JS translations.
  • All catalogs are regenerated once, without line numbers. After this, code changes touch languages/ only when a string is added, removed or moved to another file.
  • AGENTS.md notes the new behaviour.

Verification

  • The generated JSON translation files are byte-for-byte identical before and after the change.
  • composer validate-translations: OK. composer untranslated: no untranslated strings.
  • Regeneration is idempotent: running make-translations twice leaves no diff.

@github-actions

Copy link
Copy Markdown
Contributor

Test in WordPress Playground

Test the plugin with the code from this branch:

Preview in WordPress Playground

ℹ️ The eXeLearning editor is fetched from the shared release and unpacked into the plugin when the playground boots, so the first load may take a few extra seconds. ELP upload, shortcode, Gutenberg block and preview work normally.

@codecov-commenter

codecov-commenter commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.40%. Comparing base (214cf2a) to head (bc32141).

Additional details and impacted files
@@            Coverage Diff            @@
##               main     #148   +/-   ##
=========================================
  Coverage     96.40%   96.40%           
  Complexity      827      827           
=========================================
  Files            36       36           
  Lines          4233     4233           
=========================================
  Hits           4081     4081           
  Misses          152      152           
Flag Coverage Δ
javascript 95.71% <ø> (ø)
php 96.63% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

wp i18n make-pot writes #: file:line references, so any change that shifted a
translatable string's line rewrote the POT and all ten PO files, and CI's
check-translations required committing that churn with the code. Strip the
line numbers (and repeated files) from the POT before the PO files are
updated. File names stay: wp i18n make-json needs them to map JavaScript
strings to their scripts, and the generated JSON is byte-for-byte unchanged.

This regenerates every catalog once, without line numbers.
@erseco
erseco force-pushed the feature/pot-file-references branch from 9184b21 to bc32141 Compare September 26, 2026 10:50
@erseco
erseco merged commit 433e8c8 into main Sep 26, 2026
5 checks passed
@erseco
erseco deleted the feature/pot-file-references branch September 26, 2026 11:08
erseco added a commit that referenced this pull request Sep 26, 2026
Register the editor and export bridges with wp_register_script(), add their
configuration with wp_add_inline_script( ..., 'before' ) and print only that
handle with wp_print_scripts(), so the review's 'use wp_enqueue commands'
applies literally, as it already did for the editor page's CSS.

The export bridge stays deferred on every supported version: WordPress 6.3+
honours wp_script_add_data( ..., 'strategy', 'defer' ); for 6.1 and 6.2 a
script_loader_tag filter, scoped to that handle and removed right after the
print, adds the attribute. Checked on WordPress 6.1.14 and 6.3.12.

Also register the embed scripts on init instead of wp_enqueue_scripts, so the
shortcode can enqueue them in contexts where that hook never fires (the
/embed/ template, previews), and restore the AGENTS.md note from #148 that an
earlier rebase of this branch dropped.
erseco added a commit that referenced this pull request Sep 27, 2026
…kup (#125)

* fix: serve embed behavior as an enqueued script instead of inline markup

WordPress.org asked that plugins stop printing <script> and <style> blocks by
hand. The frontend printed three:

- the block and the shortcode each emitted an inline fullscreen/poster script
  per embed. One delegated script, assets/js/exelearning-embed.js, replaces
  both; it is registered with the block's other frontend assets and enqueued
  only when an embed renders.
- ExeLearning_Viewer_Enhancements printed a <style> and a ResizeObserver
  <script> to turn a percentage height into pixels. CSS aspect-ratio gives
  the same box without script, so the class is removed.

The editor and export pages are standalone HTML documents written without a
theme header, so their tags are built with wp_get_inline_script_tag() and
wp_get_script_tag() (WordPress 5.7+), keeping the export bridge deferred as
before, and the editor page's CSS goes through wp_add_inline_style().

* Print the standalone pages' bridge through the script queue

Register the editor and export bridges with wp_register_script(), add their
configuration with wp_add_inline_script( ..., 'before' ) and print only that
handle with wp_print_scripts(), so the review's 'use wp_enqueue commands'
applies literally, as it already did for the editor page's CSS.

The export bridge stays deferred on every supported version: WordPress 6.3+
honours wp_script_add_data( ..., 'strategy', 'defer' ); for 6.1 and 6.2 a
script_loader_tag filter, scoped to that handle and removed right after the
print, adds the attribute. Checked on WordPress 6.1.14 and 6.3.12.

Also register the embed scripts on init instead of wp_enqueue_scripts, so the
shortcode can enqueue them in contexts where that hook never fires (the
/embed/ template, previews), and restore the AGENTS.md note from #148 that an
earlier rebase of this branch dropped.

* Enqueue the standalone pages' handles and harden the pre-6.3 defer fallback

Enqueue the editor and export bridges and the editor page style before
printing them, so the code reads as the review asked: register, enqueue,
add inline, print.

The WordPress < 6.3 defer fallback matched the exact tag serialization
(id='…-js'>). It now adds defer to the first <script> tag with a src in the
handle's output, which skips the inline config printed in the same string,
and leaves a tag that already has defer alone. A test simulates pre-6.3 core
to cover it; checked again on WordPress 6.1.14 and 6.3.12.

Also cover the remaining branches of exelearning-embed.js: the legacy Edge
fullscreen request, a control outside any embed, and a non-element target.

* Restore the WordPress version in the pre-6.3 defer test even if it fails
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.

2 participants