Skip to content

Parse Accept-Language header in wp_load_translations_early - #6623

Open
swissspidy wants to merge 30 commits into
WordPress:trunkfrom
swissspidy:fix/30049
Open

Parse Accept-Language header in wp_load_translations_early#6623
swissspidy wants to merge 30 commits into
WordPress:trunkfrom
swissspidy:fix/30049

Conversation

@swissspidy

@swissspidy swissspidy commented May 24, 2024

Copy link
Copy Markdown
Member

Parse Accept-Language header when loading translations early where the current locale can't be fetched from the database.

Trac ticket: https://core.trac.wordpress.org/ticket/30049


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented May 24, 2024

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props swissspidy, ocean90, sabernhardt.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
@swissspidy
swissspidy requested a review from ocean90 May 29, 2024 10:55
@swissspidy
swissspidy requested a review from johnbillion May 29, 2024 15:43
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/load.php
@swissspidy
swissspidy requested a review from ocean90 June 18, 2024 18:04
Copilot AI review requested due to automatic review settings June 29, 2026 09:34

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.

Pull request overview

Adds early-l10n fallback behavior by parsing the browser’s Accept-Language header when WordPress can’t yet determine the locale from the database, so the maintenance screen (and other early output) can be localized sooner.

Changes:

  • Add get_locales_from_accept_language_header() helper to derive candidate locales from Accept-Language.
  • Use that helper in wp_load_translations_early() to expand the locale candidates list.
  • Add PHPUnit coverage for parsing behavior and expand the maintenance-mode E2E spec to assert a localized variant.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
src/wp-includes/load.php Adds formatting helpers and merges locales derived from Accept-Language into early-translation locale candidates.
src/wp-includes/l10n.php Introduces get_locales_from_accept_language_header() to parse/sort language tags and map them to WordPress locales.
tests/phpunit/tests/l10n.php Adds data-driven tests for get_locales_from_accept_language_header().
tests/e2e/specs/maintenance-mode.test.js Adds a localized maintenance-mode assertion using a German locale.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wp-includes/l10n.php Outdated
Comment thread src/wp-includes/l10n.php Outdated
Comment thread tests/phpunit/tests/l10n.php Outdated
Comment thread src/wp-includes/load.php Outdated
Comment on lines +479 to +484
if ( $has_transient ) {
// Fetches available translations and stores them in a transient.
require_once ABSPATH . 'wp-admin/includes/translation-install.php';

wp_get_available_translations();
} else {
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

4 participants