From fda3c3e23369fc06dc6832a4719fe9421d929fc1 Mon Sep 17 00:00:00 2001 From: Ramon Fincken Date: Mon, 17 Jun 2024 15:45:30 +0200 Subject: [PATCH 1/2] [TASK] Try to read HTTP_ACCEPT_LANGUAGE, if present. Allow for ISO. Added inline documentation --- src/wp-includes/load.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 6b743d459aa7b..6162dc7c7ad3e 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -1532,6 +1532,18 @@ function wp_load_translations_early() { $locales[] = $wp_local_package; } + // Try the browser's locale + // Developer note: This global variable is not present in commandline such as WP-CLI or php + if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { + // Test for regular presence, ignore wildcard https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language + // ISO country is always 2 characters (lowercase) + // followed by minus (-) sign + // followed by mixed set of as many of minus (-) sign and a-z (uppercase) + if ( preg_match( '#[a-z]{2}-[A-Z-]+#', trim( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ), $matches ) ) { + $locales[] = str_replace( '-', '_', $matches[0] ); + } + } + if ( ! $locales ) { break; } From 462d5ade18529d7b15f69f93d432f756e9c02563 Mon Sep 17 00:00:00 2001 From: Ramon Fincken Date: Mon, 17 Jun 2024 15:49:18 +0200 Subject: [PATCH 2/2] [TASK] Try to read HTTP_ACCEPT_LANGUAGE, if present. Allow for ISO. Added inline documentation, codestyle --- src/wp-includes/load.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/load.php b/src/wp-includes/load.php index 6162dc7c7ad3e..7ed6d23183476 100644 --- a/src/wp-includes/load.php +++ b/src/wp-includes/load.php @@ -1537,8 +1537,8 @@ function wp_load_translations_early() { if ( isset( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ) ) { // Test for regular presence, ignore wildcard https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language // ISO country is always 2 characters (lowercase) - // followed by minus (-) sign - // followed by mixed set of as many of minus (-) sign and a-z (uppercase) + // followed by minus (-) sign + // followed by mixed set of as many of minus (-) sign and a-z (uppercase) if ( preg_match( '#[a-z]{2}-[A-Z-]+#', trim( $_SERVER['HTTP_ACCEPT_LANGUAGE'] ), $matches ) ) { $locales[] = str_replace( '-', '_', $matches[0] ); }