i18n-loader: treat missing translation files (404) as expected, not errors#48772
i18n-loader: treat missing translation files (404) as expected, not errors#48772rudberga wants to merge 3 commits into
Conversation
…rrors When no language pack exists for a locale, the i18n-loader would fetch the translation file, receive a 404, and log a console.error. A 404 simply means no translations are available — this is expected, not an error. Now 404 responses return silently, matching the en_US early return. Fixes #41808 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
|
Linear ref: SEARCH-188 |
There was a problem hiding this comment.
Pull request overview
Updates the assets package i18n loader to treat missing translation JSON files (HTTP 404) as an expected “no translations available” outcome, reducing noisy console errors for locales without translation packs.
Changes:
- Return early (no error) when the translation fetch responds with HTTP 404.
- Update unit tests to expect silent resolution on 404 and add coverage for non-404 server errors (500).
- Add a changelog entry documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| projects/packages/assets/src/js/i18n-loader.js | Treats 404 translation fetch responses as a non-error early return while preserving error behavior for other non-OK responses. |
| projects/packages/assets/tests/js/i18n-loader.test.js | Updates the prior 404 “failed fetch” test to resolve and adds a new test ensuring 500 still rejects. |
| projects/packages/assets/changelog/fix-i18n-loader-404-console-error | Adds a patch-level changelog entry for the 404 handling change. |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Fixes #41808
Proposed changes
i18n-loader.js, treat HTTP 404 responses as "no translations available" instead of an error. When a site uses a language that doesn't have a Jetpack translation pack (e.g., Afrikaans for Jetpack Search), the i18n-loader would fetch the translation JSON file, receive a 404, and logconsole.error("Failed to fetch i18n data: Error: HTTP request failed: 404"). A 404 on a translation file simply means no translations exist for that locale/domain — this is an expected condition, not an error. The fix adds a 404 check that returns silently (matching the existingen_USearly return pattern), while preserving error handling for genuine failures (500s, network errors, etc.).Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
Before (without fix)
After (with fix)
console.error("Failed to fetch i18n data: ...")is goneWhat was tested
console.erroron an Afrikaans (af) site without a translation packpnpm jetpack test js packages/assets)What was not tested