Fix i18n locale fallback and missing-locale retry spam - #543
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughIntroduces per-locale candidate fallback (regional → base language), per-locale missing-locale caching, and per-locale download/load logic in the i18n module; expands tests to validate fallback and missing-locale caching behavior. Changes
Sequence DiagramsequenceDiagram
participant Client
participant i18n as i18n Module
participant Cache as Transient Cache
participant FS as File System
participant Remote as Remote Server
Client->>i18n: request translations for locale (e.g., da_DK)
activate i18n
i18n->>i18n: get_locale_candidates(da_DK) => [da_DK, da]
i18n->>Cache: check missing-locale transient for da_DK
Cache-->>i18n: miss
i18n->>FS: load_translation_file(da_DK, file)
FS-->>i18n: not found / stale
i18n->>Remote: download_translation(da_DK, file, suppress_404_logs=true)
Remote-->>i18n: 404 (recorded in last_download_status_code)
i18n->>FS: load_translation_file(da, file)
FS-->>i18n: found (or downloaded)
i18n->>Cache: set missing-locale transient for da_DK with version (MISSING_LOCALE_CACHE_TTL)
i18n->>Client: translations loaded (using da)
deactivate i18n
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0224bc4939
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Ensure file uses WordPress 6.5+ format (messages key) before loading. | ||
| if ( file_exists( $file ) ) { | ||
| $this->maybe_convert_file_format( $file ); | ||
| set_transient( $this->get_missing_locale_transient_key( $requested_locale ), $this->version, self::MISSING_LOCALE_CACHE_TTL ); |
There was a problem hiding this comment.
Cache missing locale only on definitive 404 failures
This writes the *_missing_* transient after any failed download sequence, but download_translation() returns false for temporary failures too (network WP_Error, 5xx, empty body, filesystem write issues), not just locale-not-found 404s. In those transient outage scenarios, the locale is incorrectly marked as missing for a day, so future initializations skip CDN retries and keep serving stale/no translations even after the backend recovers. Restrict missing-locale caching to cases where all candidates fail with 404.
Useful? React with 👍 / 👎.
…-fallback-pr-followup
Summary
da_DK→da) before giving upTest plan
composer run lintpnpm run pretestpnpm run test:unit:phpda_DK, confirm WCPOS loadsdatranslations whenda_DKfiles are unavailable🤖 Generated with Claude Code
Summary by CodeRabbit