Parse Accept-Language header in wp_load_translations_early - #6623
Parse Accept-Language header in wp_load_translations_early#6623swissspidy wants to merge 30 commits into
Accept-Language header in wp_load_translations_early#6623Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
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 fromAccept-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.
| 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>
Parse
Accept-Languageheader 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.