Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
d21a29b
Merge pull request #2 from WordPress/trunk
faisalahammad Apr 1, 2023
dd727aa
Merge branch 'WordPress:trunk' into trunk
faisalahammad Apr 2, 2023
656240e
Merge branch 'WordPress:trunk' into trunk
faisalahammad Apr 4, 2023
580f43d
Merge branch 'WordPress:trunk' into trunk
faisalahammad Apr 5, 2023
608e3d5
Merge branch 'WordPress:trunk' into trunk
faisalahammad Apr 11, 2023
ffaee64
Merge branch 'WordPress:trunk' into trunk
faisalahammad Jun 24, 2023
df714f0
Merge branch 'WordPress:trunk' into trunk
faisalahammad Jul 22, 2023
69a3788
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 2, 2024
1fe9e36
Merge branch 'WordPress:trunk' into trunk
faisalahammad Aug 4, 2026
c66b88f
Merge branch 'WordPress:trunk' into trunk
faisalahammad Aug 5, 2026
ebb35ce
Merge branch 'WordPress:trunk' into trunk
faisalahammad Aug 11, 2026
5bb2147
Merge branch 'WordPress:trunk' into trunk
faisalahammad Aug 21, 2026
e7fd0e5
Merge branch 'WordPress:trunk' into trunk
faisalahammad Aug 24, 2026
184d199
Merge branch 'WordPress:trunk' into trunk
faisalahammad Aug 26, 2026
67bb6ca
Merge branch 'WordPress:trunk' into trunk
faisalahammad Aug 28, 2026
630a7d7
Merge branch 'WordPress:trunk' into trunk
faisalahammad Aug 30, 2026
6053ef4
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 7, 2026
26433a6
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 9, 2026
b02375c
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 14, 2026
a283758
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 18, 2026
19ce386
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 20, 2026
26ec101
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 21, 2026
aefd6ca
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 21, 2026
dc9985d
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 22, 2026
9dcb18b
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 22, 2026
b8422cc
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 23, 2026
d698505
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 23, 2026
b1d9192
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 24, 2026
d7991f7
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 25, 2026
e0350e5
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 28, 2026
46c302b
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 29, 2026
fb5b857
Merge branch 'WordPress:trunk' into trunk
faisalahammad Sep 30, 2026
f586aef
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 1, 2026
916dc81
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 2, 2026
903b778
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 4, 2026
8e4b0bb
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 5, 2026
8ac8df6
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 6, 2026
097f90b
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 6, 2026
f3a4ed5
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 7, 2026
b46ef06
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 7, 2026
5d34771
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 8, 2026
27f38ed
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 9, 2026
f0086c6
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 11, 2026
707cfba
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 12, 2026
4ee3e5b
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 12, 2026
90c2c4e
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 13, 2026
2cc94e2
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 14, 2026
684662f
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 14, 2026
842229e
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 15, 2026
9716298
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 16, 2026
3b8875d
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 17, 2026
49d8ba6
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 18, 2026
655b84d
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 19, 2026
f16f738
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 21, 2026
6bf818c
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 21, 2026
8cdbc36
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 22, 2026
2380c4b
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 22, 2026
e76b97c
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 23, 2026
5e3b78e
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 24, 2026
6323b93
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 25, 2026
44205f3
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 26, 2026
cd6bc9a
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 27, 2026
839b240
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 28, 2026
90e5715
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 29, 2026
ddcef6e
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 31, 2026
07db7cb
Merge branch 'WordPress:trunk' into trunk
faisalahammad Oct 31, 2026
ec4557c
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 2, 2026
4b9276a
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 3, 2026
7019d13
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 4, 2026
c4c69d4
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 5, 2026
5830ebd
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 6, 2026
00446e1
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 7, 2026
33d5643
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 8, 2026
d75d6ea
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 9, 2026
f27421a
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 9, 2026
b802023
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 10, 2026
61bab52
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 11, 2026
6ee38c6
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 12, 2026
be7fe3f
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 13, 2026
0400531
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 15, 2026
3e69d0a
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 16, 2026
b5649f4
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 17, 2026
2434c55
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 18, 2026
12b84ad
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 19, 2026
ac42b10
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 19, 2026
a71ffac
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 20, 2026
f74163c
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 21, 2026
6d51f70
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 22, 2026
d39053d
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 23, 2026
79b4ad5
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 24, 2026
7b3d0d0
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 24, 2026
d95d000
Merge branch 'WordPress:trunk' into trunk
faisalahammad Nov 25, 2026
8377d12
fix(i18n): Update date and time formats when the site language changes
faisalahammad Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/wp-admin/includes/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,45 @@ function options_reading_blog_charset() {
echo '<input name="blog_charset" type="text" id="blog_charset" value="' . esc_attr( get_option( 'blog_charset' ) ) . '" class="regular-text" />';
echo '<p class="description">' . __( 'The <a href="https://wordpress.org/documentation/article/wordpress-glossary/#character-set">character encoding</a> of your site (UTF-8 is recommended)' ) . '</p>';
}

/**
* Updates the date and time formats after the site language changes.
*
* A format is only updated when it still matches the default format of the
* previous locale, so formats chosen by the user are kept.
*
* @since 7.3.0
*
* @param string $old_locale The site locale before the change.
* @param string $new_locale The site locale after the change.
*/
function wp_update_date_time_formats_on_locale_change( $old_locale, $new_locale ) {
if ( $old_locale === $new_locale ) {
return;
}

/*
* Load the translations directly, as switch_to_locale() does not know
* about language packs installed during the current request.
*/
load_default_textdomain( $old_locale );
$old_formats = array(
'date_format' => __( 'F j, Y' ),
'time_format' => __( 'g:i a' ),
);

load_default_textdomain( $new_locale );
$new_formats = array(
'date_format' => __( 'F j, Y' ),
'time_format' => __( 'g:i a' ),
);

// Restore the translations for the current user.
load_default_textdomain();

foreach ( $old_formats as $option => $old_format ) {
if ( get_option( $option ) === $old_format ) {
update_option( $option, $new_formats[ $option ] );
}
}
}
6 changes: 6 additions & 0 deletions src/wp-admin/options.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@

if ( $options ) {
$user_language_old = get_user_locale();
$site_language_old = get_locale();

foreach ( $options as $option ) {
if ( $unregistered ) {
Expand Down Expand Up @@ -357,6 +358,11 @@
* used as a fallback in get_user_locale().
*/
unset( $GLOBALS['locale'] );

if ( 'general' === $option_page ) {
wp_update_date_time_formats_on_locale_change( $site_language_old, get_locale() );
}

$user_language_new = get_user_locale();
if ( $user_language_old !== $user_language_new ) {
load_default_textdomain( $user_language_new );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/data/languages/de_DE.l10n.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['html_lang_attribute'=>'de-DE','text directionltr'=>'ltr','number_format_decimal_point'=>',','number_format_thousands_sep'=>'.','Update %s now'=>'Jetzt %s aktualisieren','[%1$s] Confirm Action: %2$s'=>'[%1$s] Aktion bestätigen: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Löschauftrag ausgeführt','[%s] Personal Data Export'=>'[%s] Export personenbezogener Daten', 'You must provide at least one recipient email address.'=>'Du musst mindestens eine Empfänger-E-Mail-Adresse angeben.'],'language'=>'de_DE','x-generator'=>'Poedit 2.2.1'];
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['F j, Y'=>'j. F Y','g:i a'=>'G:i','html_lang_attribute'=>'de-DE','text directionltr'=>'ltr','number_format_decimal_point'=>',','number_format_thousands_sep'=>'.','Update %s now'=>'Jetzt %s aktualisieren','[%1$s] Confirm Action: %2$s'=>'[%1$s] Aktion bestätigen: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Löschauftrag ausgeführt','[%s] Personal Data Export'=>'[%s] Export personenbezogener Daten', 'You must provide at least one recipient email address.'=>'Du musst mindestens eine Empfänger-E-Mail-Adresse angeben.'],'language'=>'de_DE','x-generator'=>'Poedit 2.2.1'];
Binary file modified tests/phpunit/data/languages/de_DE.mo
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/phpunit/data/languages/de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ msgstr "[%s] Export personenbezogener Daten"
#: wp-includes/class-wp-phpmailer.php:71
msgid "You must provide at least one recipient email address."
msgstr "Du musst mindestens eine Empfänger-E-Mail-Adresse angeben."

#. translators: Default date format, see https://www.php.net/manual/datetime.format.php
#: wp-admin/includes/schema.php:436
msgid "F j, Y"
msgstr "j. F Y"

#. translators: Default time format, see https://www.php.net/manual/datetime.format.php
#: wp-admin/includes/schema.php:438
msgid "g:i a"
msgstr "G:i"
2 changes: 1 addition & 1 deletion tests/phpunit/data/languages/es_ES.l10n.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?php
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['text directionltr'=>'ltr','<strong>ERROR</strong>: Sorry, that username is not allowed.'=>'<strong>ERROR</strong>: Lo siento, ese nombre de usuario no está permitido.','Invalid parameter.'=>'Parámetro no válido. ','menu location(Current: %s)'=>'(Actual: %s)','menu(Currently set to: %s)'=>'(Actualmente fijado en: %s)','[%1$s] Confirm Action: %2$s'=>'[%1$s] Confirmar la acción: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Solicitud de borrado completada','[%s] Personal Data Export'=>'[%s] Exportación de datos personales', 'Manual Offsets' => 'Compensaciones manuales', 'Select a city' => 'Elige una ciudad' ],'language'=>'es_ES','x-generator'=>'Poedit 2.3'];
return ['domain'=>NULL,'plural-forms'=>'nplurals=2; plural=n != 1;','messages'=>['F j, Y'=>'j \\d\\e F \\d\\e Y','g:i a'=>'H:i','text directionltr'=>'ltr','<strong>ERROR</strong>: Sorry, that username is not allowed.'=>'<strong>ERROR</strong>: Lo siento, ese nombre de usuario no está permitido.','Invalid parameter.'=>'Parámetro no válido. ','menu location(Current: %s)'=>'(Actual: %s)','menu(Currently set to: %s)'=>'(Actualmente fijado en: %s)','[%1$s] Confirm Action: %2$s'=>'[%1$s] Confirmar la acción: %2$s','[%s] Erasure Request Fulfilled'=>'[%s] Solicitud de borrado completada','[%s] Personal Data Export'=>'[%s] Exportación de datos personales', 'Manual Offsets' => 'Compensaciones manuales', 'Select a city' => 'Elige una ciudad' ],'language'=>'es_ES','x-generator'=>'Poedit 2.3'];
Binary file modified tests/phpunit/data/languages/es_ES.mo
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/phpunit/data/languages/es_ES.po
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,13 @@ msgstr "[%1$s] Confirmar la acción: %2$s"
msgid "[%s] Erasure Request Fulfilled"
msgstr "[%s] Solicitud de borrado completada"


#. translators: Default date format, see https://www.php.net/manual/datetime.format.php
#: wp-admin/includes/schema.php:436
msgid "F j, Y"
msgstr "j \\d\\e F \\d\\e Y"

#. translators: Default time format, see https://www.php.net/manual/datetime.format.php
#: wp-admin/includes/schema.php:438
msgid "g:i a"
msgstr "H:i"
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
/**
* Tests for wp_update_date_time_formats_on_locale_change().
*
* @group admin
* @group l10n
* @group i18n
*
* @covers ::wp_update_date_time_formats_on_locale_change
*/
class Tests_Admin_Includes_Options_WpUpdateDateTimeFormatsOnLocaleChange extends WP_UnitTestCase {

/**
* Loads the tested file.
*/
public static function set_up_before_class() {
parent::set_up_before_class();

require_once ABSPATH . 'wp-admin/includes/options.php';
}

/**
* Restores the default translations.
*/
public function tear_down() {
set_current_screen( 'front' );
load_default_textdomain();

parent::tear_down();
}

/**
* @ticket 36259
* @dataProvider data_should_update_default_formats
*
* @param string $old_locale The previous site locale.
* @param string $new_locale The new site locale.
* @param string $old_date The date format before the change.
* @param string $old_time The time format before the change.
* @param string $new_date The expected date format after the change.
* @param string $new_time The expected time format after the change.
*/
public function test_should_update_default_formats( $old_locale, $new_locale, $old_date, $old_time, $new_date, $new_time ) {
update_option( 'date_format', $old_date );
update_option( 'time_format', $old_time );

wp_update_date_time_formats_on_locale_change( $old_locale, $new_locale );

$this->assertSame( $new_date, get_option( 'date_format' ), 'The date format is not correct.' );
$this->assertSame( $new_time, get_option( 'time_format' ), 'The time format is not correct.' );
}

/**
* Data provider.
*
* @return array[]
*/
public static function data_should_update_default_formats() {
return array(
'English to German, default formats' => array( 'en_US', 'de_DE', 'F j, Y', 'g:i a', 'j. F Y', 'G:i' ),
'German to Spanish, default formats' => array( 'de_DE', 'es_ES', 'j. F Y', 'G:i', 'j \d\e F \d\e Y', 'H:i' ),
'Spanish to English, default formats' => array( 'es_ES', 'en_US', 'j \d\e F \d\e Y', 'H:i', 'F j, Y', 'g:i a' ),
'English to German, custom date' => array( 'en_US', 'de_DE', 'Y-m-d', 'g:i a', 'Y-m-d', 'G:i' ),
'English to German, custom time' => array( 'en_US', 'de_DE', 'F j, Y', 'H:i:s', 'j. F Y', 'H:i:s' ),
'English to German, custom formats' => array( 'en_US', 'de_DE', 'd M Y', 'g:i A', 'd M Y', 'g:i A' ),
'German to English, English formats' => array( 'de_DE', 'en_US', 'F j, Y', 'g:i a', 'F j, Y', 'g:i a' ),
'Same locale, other locale defaults' => array( 'en_US', 'en_US', 'j. F Y', 'G:i', 'j. F Y', 'G:i' ),
);
}

/**
* @ticket 36259
*/
public function test_should_restore_translations_of_current_locale() {
wp_update_date_time_formats_on_locale_change( 'en_US', 'de_DE' );

$this->assertSame( 'F j, Y', __( 'F j, Y' ) );
}

/**
* @ticket 36259
*/
public function test_should_use_site_locales_when_user_locale_differs() {
$user_id = self::factory()->user->create(
array(
'role' => 'administrator',
'locale' => 'de_DE',
)
);
wp_set_current_user( $user_id );
set_current_screen( 'options-general' );

update_option( 'date_format', 'j \d\e F \d\e Y' );
update_option( 'time_format', 'H:i' );

wp_update_date_time_formats_on_locale_change( 'es_ES', 'en_US' );

$this->assertSame( 'F j, Y', get_option( 'date_format' ), 'The date format is not correct.' );
$this->assertSame( 'g:i a', get_option( 'time_format' ), 'The time format is not correct.' );
$this->assertSame( 'j. F Y', __( 'F j, Y' ), 'The translations of the user locale were not restored.' );
}
}
Loading