Repository navigation
I18N: Switching language should update date and time formats - #16243
faisalahammad wants to merge 93 commits into
Conversation
- Add wp_update_date_time_formats_on_locale_change() to wp-admin/includes/options.php. - Call it from wp-admin/options.php after the General settings are saved. - Add date and time format strings to the de_DE and es_ES test translations. - Add unit tests. Why: the date and time formats stayed on the old language defaults after switching the site language. A format is only updated when it still matches the previous locale default, so custom formats are kept. See #36259.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. 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. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
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.
🟢 Approval recommended
No active review issues block the locale-aware date and time format update.
No open issues 🎉
What changed in this PR
Updates WordPress General settings so changing the site language also updates date and time formats that match the previous language’s defaults, while preserving custom formats.
Changes:
- Adds a helper to compare locale defaults, update matching formats, and restore the current user’s translations.
- Calls the helper after General settings are saved.
- Adds unit tests and translation fixtures for locale changes, custom formats, and differing user languages.
| File | Description |
|---|---|
tests/phpunit/tests/admin/includes/options/wpUpdateDateTimeFormatsOnLocaleChange.php |
Tests format updates, custom-format preservation, and translation restoration. |
tests/phpunit/data/languages/es_ES.po |
Adds Spanish default date and time translations. |
tests/phpunit/data/languages/es_ES.l10n.php |
Adds matching Spanish runtime translation fixtures. |
tests/phpunit/data/languages/de_DE.po |
Adds German default date and time translations. |
tests/phpunit/data/languages/de_DE.l10n.php |
Adds matching German runtime translation fixtures. |
src/wp-admin/options.php |
Captures the previous site locale and invokes format updates after saving. |
src/wp-admin/includes/options.php |
Implements locale-aware date and time format updates. |
Review effort: Balanced
When the site language is changed in Settings > General, the date and time formats now switch to the new language's defaults. A format is only changed when it still matches the old language's default, so custom formats are kept.
Trac ticket: https://core.trac.wordpress.org/ticket/36259
What changed
wp_update_date_time_formats_on_locale_change( $old_locale, $new_locale )inwp-admin/includes/options.php. It loads the default translations of both site locales, compares the saveddate_formatandtime_formatoptions with the old locale's defaults, and updates the ones that match. Then it restores the translations for the current user.wp-admin/options.phpstoresget_locale()before saving and calls the new function after the General settings are saved.load_default_textdomain()is used instead ofswitch_to_locale(), becauseswitch_to_locale()does not know about a language pack downloaded during the same request.Compared to the earlier patches on the ticket:
$_POSTvalues, so formats with backslashes likeG\hi(French) orj \d\e F \d\e Y(Spanish) are matched.Scope
WPLANGthrough the REST API (/wp/v2/settings) or the abilities API. These can be handled in a follow-up.links_updated_date_formatis not changed.Testing
Unit tests:
Manual test:
F j, Y/g:i a).j. F Yand the Time Format toG:i.Y-m-d, switch to another language and save. The custom date format stays, and only the time format changes.j F Y/G\hi) back to English. The formats change toF j, Y/g:i a.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigating the ticket, drafting the fix and unit tests. I reviewed, tested and edited the final code.
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.