Skip to content

Pattern Translations: Skip locales without any translations - #790

Merged
obenland merged 5 commits into
trunkfrom
fix/skip-untranslated-locales
Oct 8, 2026
Merged

obenland merged 5 commits into
trunkfrom
fix/skip-untranslated-locales

Conversation

@obenland

@obenland obenland commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #789. The translation import still takes ~520s per 15-minute chunk, about half a Cavalcade worker around the clock. Most of that is spent on locales that can't produce a translation.

Each chunk processes 50 patterns × ~203 locales. For every pair, Pattern::to_locale() switches locale and runs one GlotPress_Translate_Bridge query per string. The bridge caches for 6h, but each pattern only comes around every 12h, so every lookup hits the database. Of the 207 translation sets in patterns/core, only 64 have any current translations (see https://translate.wordpress.org/api/projects/patterns/core/). The other 143 account for ~7,150 of the ~10,150 pattern/locale pairs per chunk, and every one of them ends in "No Translations exist yet."

This PR looks up once per run which translation sets in the patterns project have at least one current translation of an active original (the same conditions the bridge uses), maps them to WordPress locales via GP_Locales (variants like de/formal are locales of their own), and only processes those. If GlotPress isn't available or the lookup returns nothing, every locale is processed as before. A locale's first translation is picked up on the next chunk, since the list is rebuilt each run.

Expected: chunk runtime drops by roughly two thirds, assuming per-locale cost is similar for empty and translated locales. Not profiled.

How to test the changes in this Pull Request:

  1. On a sandbox, wp shell --url=https://wordpress.org/patterns/ and run WordPressdotorg\Pattern_Translations\Cron\get_translated_locales();. It should return ~64 WordPress locales, matching the sets with current_count > 0 in the API above, including variants such as de_DE_formal and nl_NL_formal.
  2. After deploy, the job log's "Processing N Patterns in M locales." should show M ≈ 64 instead of ~203, and chunk durations for pattern_import_translations_to_directory should fall well below ~520s.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Translation imports now prioritize locales with current translations for active patterns. When no matching locales are found, imports continue to include all locales.

The translation import checked every pattern in every locale, but most
locales have no pattern translations at all, so each of those lookups
switched locale and queried every string only to find nothing. About two
thirds of each run went to locales that cannot produce a translation.

Look up once per run which locales have at least one current translation
in the patterns project, and only process those. When that lookup is not
possible, every locale is processed as before.
Copilot AI balanced review requested due to automatic review settings October 8, 2026 15:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d11823f6-f6fc-4d9b-b84e-1812b696df9d
📥 Commits

Reviewing files that changed from the base of the PR and between f51e44a and 0991675.

📒 Files selected for processing (1)
  • public_html/wp-content/plugins/pattern-translations/includes/cron.php
 ___________________________________________________________________________________________________
< Little bunny Foo Foo, hopping through the code, picking up the bugs and bopping them on the head. >
 ---------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c04dd5a0-0786-4ef5-8c3b-c0403b09b38d
📥 Commits

Reviewing files that changed from the base of the PR and between 6b6982f and f51e44a.

📒 Files selected for processing (1)
  • public_html/wp-content/plugins/pattern-translations/includes/cron.php

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

The translation import cron now identifies locales with current translations in the configured GlotPress project. When this locale list is non-empty, the cron limits processing to those locales. If the list is empty, it keeps the existing locale list.

Changes

Translation locale filtering

Layer / File(s) Summary
Resolve translated locales and filter imports
public_html/wp-content/plugins/pattern-translations/includes/cron.php
get_translated_locales() returns WordPress locales for translation sets with current translations of active originals. The import job filters its available locales when this result is non-empty. If GP_Locales is unavailable or no locales are returned, the helper returns an empty list and the job keeps all available locales.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Refactor

Merge Risk: ⚪ Minimal · up to f51e4

No concrete regression is established. The locale filter is ready to merge after normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: skipping locales that have no translations.
Description check ✅ Passed The description explains the motivation, implementation, fallback behavior, expected impact, related PR, and testing steps. It omits the Props entry and does not use the template's Fixes/See format, b…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Use identifier placeholders for the prefixed table names instead of
interpolating them into the query.
Derive the locale of a variant translation set from its base locale and
the set slug, the inverse of how the GlotPress bridge looks translations
up. Looking the variant up by its own slug missed locales whose slug does
not follow the set, such as Valencian Catalan, so the filter would have
dropped them once they had translations.
Check for the GlotPress table prefix itself instead of the locales class,
which is always loaded, and use it without a default, as the rest of the
plugin does. Log when the locale list cannot be built and every locale is
processed instead.
@obenland
obenland merged commit a5831d2 into trunk Oct 8, 2026
4 of 5 checks passed
@obenland
obenland deleted the fix/skip-untranslated-locales branch October 8, 2026 15:27
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