From 8df80ae3ee3f3b6aa44ad53cb63de61c042cb0e9 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 1 Nov 2016 09:16:31 +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. Built from https://develop.svn.wordpress.org/trunk@39068 git-svn-id: http://core.svn.wordpress.org/trunk@39010 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/options-general.php | 2 +- wp-includes/functions.php | 16 ++++++++++------ wp-includes/version.php | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/wp-admin/options-general.php b/wp-admin/options-general.php index 7b1c999277..22d475c2e2 100644 --- a/wp-admin/options-general.php +++ b/wp-admin/options-general.php @@ -147,7 +147,7 @@ if ( empty($tzstring) ) { // Create a UTC+- zone if no timezone string exists

diff --git a/wp-includes/functions.php b/wp-includes/functions.php index ff489ae869..32fa55c9df 100644 --- a/wp-includes/functions.php +++ b/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; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4cf070d946..152badad63 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-beta1-39067'; +$wp_version = '4.7-beta1-39068'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.