Make WordPress Core

Changeset 39068


Ignore:
Timestamp:
11/01/2016 09:15:42 AM (10 years ago)
Author:
swissspidy
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/options-general.php

    r38720 r39068  
    148148
    149149<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">
    150 <?php echo wp_timezone_choice($tzstring); ?>
     150        <?php echo wp_timezone_choice( $tzstring, get_user_locale() ); ?>
    151151</select>
    152152
  • trunk/src/wp-includes/functions.php

    r38991 r39068  
    45024502 *
    45034503 * @since 2.9.0
     4504 * @since 4.7.0 Added the `$locale` parameter.
    45044505 *
    45054506 * @staticvar bool $mo_loaded
     4507 * @staticvar string $locale_loaded
    45064508 *
    45074509 * @param string $selected_zone Selected timezone.
     4510 * @param string $locale        Optional. Locale to load the timezones in. Default current site locale.
    45084511 * @return string
    45094512 */
    4510 function wp_timezone_choice( $selected_zone ) {
    4511         static $mo_loaded = false;
     4513function wp_timezone_choice( $selected_zone, $locale = null ) {
     4514        static $mo_loaded = false, $locale_loaded = null;
    45124515
    45134516        $continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific');
    45144517
    4515         // Load translations for continents and cities
    4516         if ( !$mo_loaded ) {
    4517                 $locale = get_locale();
    4518                 $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo';
     4518        // Load translations for continents and cities.
     4519        if ( ! $mo_loaded || $locale !== $locale_loaded ) {
     4520                $locale_loaded = $locale ? $locale : get_locale();
     4521                $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo';
     4522                unload_textdomain( 'continents-cities' );
    45194523                load_textdomain( 'continents-cities', $mofile );
    45204524                $mo_loaded = true;
Note: See TracChangeset for help on using the changeset viewer.