From b0aad156bbac2c334bd1ac60ca13a8c6283e4c2a Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 1 Nov 2016 09:15:42 +0000 Subject: [PATCH] I18N: Show available timezones in the user's locale on the settings screen. Adds a `$locale` parameter to `wp_timezone_choice()` to only reload translations when necessary. Props yale01. See #38485. git-svn-id: https://develop.svn.wordpress.org/trunk@39068 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/options-general.php | 2 +- src/wp-includes/functions.php | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/wp-admin/options-general.php b/src/wp-admin/options-general.php index 7b1c999277..22d475c2e2 100644 --- a/src/wp-admin/options-general.php +++ b/src/wp-admin/options-general.php @@ -147,7 +147,7 @@ if ( empty($tzstring) ) { // Create a UTC+- zone if no timezone string exists

diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index ff489ae869..32fa55c9df 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -4501,21 +4501,25 @@ function _wp_timezone_choice_usort_callback( $a, $b ) { * Gives a nicely-formatted list of timezone strings. * * @since 2.9.0 + * @since 4.7.0 Added the `$locale` parameter. * * @staticvar bool $mo_loaded + * @staticvar string $locale_loaded * * @param string $selected_zone Selected timezone. + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. * @return string */ -function wp_timezone_choice( $selected_zone ) { - static $mo_loaded = false; +function wp_timezone_choice( $selected_zone, $locale = null ) { + static $mo_loaded = false, $locale_loaded = null; $continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'); - // Load translations for continents and cities - if ( !$mo_loaded ) { - $locale = get_locale(); - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; + // Load translations for continents and cities. + if ( ! $mo_loaded || $locale !== $locale_loaded ) { + $locale_loaded = $locale ? $locale : get_locale(); + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; + unload_textdomain( 'continents-cities' ); load_textdomain( 'continents-cities', $mofile ); $mo_loaded = true; }