Skip to content

i18n-loader: treat missing translation files (404) as expected, not errors#48772

Open
rudberga wants to merge 3 commits into
trunkfrom
fix/i18n-loader-404-console-error
Open

i18n-loader: treat missing translation files (404) as expected, not errors#48772
rudberga wants to merge 3 commits into
trunkfrom
fix/i18n-loader-404-console-error

Conversation

@rudberga
Copy link
Copy Markdown

@rudberga rudberga commented May 13, 2026

Fixes #41808

Proposed changes

  • Fix: In 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 log console.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 existing en_US early return pattern), while preserving error handling for genuine failures (500s, network errors, etc.).
  • Tests: Updated the existing "Failed fetch" test (which used 404) to expect silent resolution, and added a new "Failed fetch (500)" test to verify server errors still throw.

Related product discussion/links

  • Internal: p1739480350788039/1738683024.939459-slack-C02ME06LF (referenced in issue)

Does this pull request change what data or activity we track or use?

No.

Testing instructions

Before (without fix)

  1. Go to https://national-rhinoceros-woodpecker.jurassic.ninja/ (site set to Afrikaans, a language without a Jetpack Search translation pack)
  2. Open the browser console (DevTools → Console)
  3. Trigger Instant Search (click the search bar / search widget)
  4. Observe the console error:
    Failed to fetch i18n data: Error: HTTP request failed: 404
    
image

After (with fix)

  1. Go to https://lovely-exceptional.jurassic.ninja/ (test site with fix applied, also set to Afrikaans)
  2. Open the browser console and trigger Instant Search
  3. Observe: the console.error("Failed to fetch i18n data: ...") is gone
  4. The 404 still appears in the Network tab (expected — the browser logs all HTTP requests), but the noisy JS error is eliminated
  5. Search still works correctly with English fallback strings
image

What was tested

  • Verified fix eliminates the console.error on an Afrikaans (af) site without a translation pack
  • All 13 unit tests pass (pnpm jetpack test js packages/assets)
  • Confirmed other HTTP errors (500) still throw as expected (new test)
  • Ran /jetpack-review-pr — passed with no blockers or suggestions

What was not tested

  • Other languages without translation packs (expected to behave the same — the fix is locale-agnostic)
  • Jetpack Search plugin standalone (tested via Jetpack core plugin which shares the same i18n-loader)

…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>
@rudberga rudberga added the [Status] Needs Review This PR is ready for review. label May 13, 2026
@rudberga rudberga self-assigned this May 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the fix/i18n-loader-404-console-error branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/i18n-loader-404-console-error
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/i18n-loader-404-console-error

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control
Copy link
Copy Markdown

jp-launch-control Bot commented May 13, 2026

Code Coverage Summary

Coverage changed in 1 file.

File Coverage Δ% Δ Uncovered
projects/packages/assets/src/js/i18n-loader.js 29/29 (100.00%) 0.00% 0 💚

Full summary · PHP report · JS report

@rudberga
Copy link
Copy Markdown
Author

Linear ref: SEARCH-188

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread projects/packages/assets/src/js/i18n-loader.js
Comment thread projects/packages/assets/changelog/fix-i18n-loader-404-console-error Outdated
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@rudberga rudberga requested a review from anomiex May 13, 2026 07:03
@rudberga
Copy link
Copy Markdown
Author

Adding @anomiex as reviewer as you were mentioned in the GH Issue as being the one who investigated this. Please let me know if I should request from someone else, thank you! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search: if language pack isn't available to load, it create a errors (404 showing in the console)

2 participants