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
This commit is contained in:
Pascal Birchler 2016-11-01 09:16:31 +00:00
parent d7d8768ffd
commit 8df80ae3ee
3 changed files with 12 additions and 8 deletions

View File

@ -147,7 +147,7 @@ if ( empty($tzstring) ) { // Create a UTC+- zone if no timezone string exists
<td> <td>
<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description"> <select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">
<?php echo wp_timezone_choice($tzstring); ?> <?php echo wp_timezone_choice( $tzstring, get_user_locale() ); ?>
</select> </select>
<p class="description" id="timezone-description"><?php _e( 'Choose either a city in the same timezone as you or a UTC timezone offset.' ); ?></p> <p class="description" id="timezone-description"><?php _e( 'Choose either a city in the same timezone as you or a UTC timezone offset.' ); ?></p>

View File

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

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.