Make WordPress Core

Ticket #29395: 29395.3.patch

File 29395.3.patch, 9.7 KB (added by ocean90, 10 years ago)
  • src/wp-admin/css/forms.css

     
    611611        font-size: 13px;
    612612}
    613613
    614 table.form-table td .updated p { 
    615         font-size: 13px; 
    616         margin: 0.3em 0; 
     614table.form-table td .updated p {
     615        font-size: 13px;
     616        margin: 0.3em 0;
    617617}
    618618
    619619/*------------------------------------------------------------------------------
     
    767767        margin: -3px 3px;
    768768}
    769769
     770.settings-php .language-install-spinner,
     771.options-general-php .language-install-spinner {
     772        display: inline-block;
     773        float: none;
     774        margin: -3px 5px 0;
     775        vertical-align: middle;
     776}
     777
    770778/* =Media Queries
    771779-------------------------------------------------------------- */
    772780
  • src/wp-admin/network/settings.php

     
    1010/** Load WordPress Administration Bootstrap */
    1111require_once( dirname( __FILE__ ) . '/admin.php' );
    1212
     13/** WordPress Translation Install API */
     14require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     15
    1316if ( ! is_multisite() )
    1417        wp_die( __( 'Multisite support is not enabled.' ) );
    1518
     
    1922$title = __( 'Network Settings' );
    2023$parent_file = 'settings.php';
    2124
     25/**
     26 * Display JavaScript on the page.
     27 *
     28 * @since 4.1.0
     29*/
     30function network_settings_add_js() {
     31?>
     32<script type="text/javascript">
     33jQuery(document).ready( function($) {
     34        var languageSelect = $( '#WPLANG' );
     35        $( 'form' ).submit( function() {
     36                // Don't show a spinner for English and installed languages,
     37                // as there is nothing to download.
     38                if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
     39                        $( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
     40                }
     41        });
     42});
     43</script>
     44<?php
     45}
     46add_action( 'admin_head', 'network_settings_add_js' );
     47
    2248get_current_screen()->add_help_tab( array(
    2349                'id'      => 'overview',
    2450                'title'   => __('Overview'),
     
    5884                'illegal_names', 'limited_email_domains', 'banned_email_domains', 'WPLANG', 'admin_email',
    5985        );
    6086
     87        // Handle translation install.
     88        if ( ! empty( $_POST['WPLANG'] ) && wp_can_install_language_pack() ) {  // @todo: Skip if already installed
     89                $language = wp_download_language_pack( $_POST['WPLANG'] );
     90                if ( $language ) {
     91                        $_POST['WPLANG'] = $language;
     92                }
     93        }
     94
    6195        foreach ( $options as $option_name ) {
    6296                if ( ! isset($_POST[$option_name]) )
    6397                        continue;
     
    275309
    276310                <?php
    277311                $languages = get_available_languages();
    278                 if ( ! empty( $languages ) ) {
     312                $translations = wp_get_available_translations();
     313                if ( ! empty( $languages ) || ! empty( $translations ) ) {
    279314                        ?>
    280315                        <h3><?php _e( 'Language Settings' ); ?></h3>
    281316                        <table class="form-table">
     
    289324                                                }
    290325
    291326                                                wp_dropdown_languages( array(
    292                                                         'name'      => 'WPLANG',
    293                                                         'id'        => 'WPLANG',
    294                                                         'selected'  => $lang,
    295                                                         'languages' => $languages,
     327                                                        'name'         => 'WPLANG',
     328                                                        'id'           => 'WPLANG',
     329                                                        'selected'     => $lang,
     330                                                        'languages'    => $languages,
     331                                                        'translations' => $translations,
     332                                                        'show_available_translations' => wp_can_install_language_pack(),
    296333                                                ) );
    297334                                                ?>
    298335                                        </td>
  • src/wp-admin/options-general.php

     
    99/** WordPress Administration Bootstrap */
    1010require_once( dirname( __FILE__ ) . '/admin.php' );
    1111
     12/** WordPress Translation Install API */
     13require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     14
    1215if ( ! current_user_can( 'manage_options' ) )
    1316        wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
    1417
     
    6366                                        date : format.val()
    6467                                }, function(d) { format.siblings('.spinner').hide(); format.siblings('.example').text(d); } );
    6568                });
     69
     70                var languageSelect = $( '#WPLANG' );
     71                $( 'form' ).submit( function() {
     72                        // Don't show a spinner for English and installed languages,
     73                        // as there is nothing to download.
     74                        if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
     75                                $( '#submit', this ).after( '<span class="spinner language-install-spinner" />' );
     76                        }
     77                });
    6678        });
    6779//]]>
    6880</script>
     
    318330
    319331<?php
    320332$languages = get_available_languages();
     333$translations = wp_get_available_translations();
    321334if ( ! is_multisite() && defined( 'WPLANG' ) && '' !== WPLANG && 'en_US' !== WPLANG && ! in_array( WPLANG, $languages ) ) {
    322335        $languages[] = WPLANG;
    323336}
    324 if ( $languages ) {
     337if ( ! empty( $languages ) || ! empty( $translations ) ) {
    325338        ?>
    326339        <tr>
    327340                <th width="33%" scope="row"><label for="WPLANG"><?php _e( 'Site Language' ); ?></label></th>
     
    333346                        }
    334347
    335348                        wp_dropdown_languages( array(
    336                                 'name'      => 'WPLANG',
    337                                 'id'        => 'WPLANG',
    338                                 'selected'  => $locale,
    339                                 'languages' => $languages,
     349                                'name'         => 'WPLANG',
     350                                'id'           => 'WPLANG',
     351                                'selected'     => $locale,
     352                                'languages'    => $languages,
     353                                'translations' => $translations,
     354                                'show_available_translations' => ( ! is_multisite() || is_super_admin() ) && wp_can_install_language_pack(),
    340355                        ) );
    341356
    342357                        // Add note about deprecated WPLANG constant.
  • src/wp-admin/options.php

     
    151151                $options = $whitelist_options[ $option_page ];
    152152        }
    153153
    154         // Handle custom date/time formats.
    155154        if ( 'general' == $option_page ) {
     155                // Handle custom date/time formats.
    156156                if ( !empty($_POST['date_format']) && isset($_POST['date_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['date_format'] ) )
    157157                        $_POST['date_format'] = $_POST['date_format_custom'];
    158158                if ( !empty($_POST['time_format']) && isset($_POST['time_format_custom']) && '\c\u\s\t\o\m' == wp_unslash( $_POST['time_format'] ) )
     
    163163                        $_POST['gmt_offset'] = preg_replace('/UTC\+?/', '', $_POST['gmt_offset']);
    164164                        $_POST['timezone_string'] = '';
    165165                }
     166
     167                // Handle translation install.
     168                if ( ! empty( $_POST['WPLANG'] ) && ( ! is_multisite() || is_super_admin() ) ) { // @todo: Skip if already installed
     169                        require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     170
     171                        if ( wp_can_install_language_pack() ) {
     172                                $language = wp_download_language_pack( $_POST['WPLANG'] );
     173                                if ( $language ) {
     174                                        $_POST['WPLANG'] = $language;
     175                                }
     176                        }
     177                }
    166178        }
    167179
    168180        if ( $options ) {
  • src/wp-includes/l10n.php

     
    852852 * @param array $args Optional arguments. Default empty array.
    853853 */
    854854function wp_dropdown_languages( $args = array() ) {
    855         require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
    856855
    857856        $args = wp_parse_args( $args, array(
    858                 'id'        => '',
    859                 'name'      => '',
    860                 'languages' => array(),
    861                 'selected'  => ''
     857                'id'           => '',
     858                'name'         => '',
     859                'languages'    => array(),
     860                'translations' => array(),
     861                'selected'     => '',
     862                'show_available_translations' => true,
    862863        ) );
    863864
    864         if ( empty( $args['languages'] ) ) {
    865                 return false;
     865        $translations = $args['translations'];
     866        if ( empty( $args['translations'] ) ) {
     867                require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     868                $translations = wp_get_available_translations();
    866869        }
    867870
    868         $translations = wp_get_available_translations();
    869 
    870871        /*
    871872         * $args['languages'] should only contain the locales. Find the locale in
    872873         * $translations to get the native name. Fall back to locale.
     
    880881                                'native_name' => $translation['native_name'],
    881882                                'lang'        => $translation['iso'][1],
    882883                        );
     884
     885                        // Remove installed language from available translations.
     886                        unset( $translations[ $locale ] );
    883887                } else {
    884888                        $languages[] = array(
    885889                                'language'    => $locale,
     
    891895
    892896        printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
    893897
     898        // Holds the HTML markup.
     899        $structure = array();
     900
    894901        // List installed languages.
    895         echo '<option value="" lang="en">English (United States)</option>';
     902        $structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
     903        $structure[] = '<option value="" lang="en" data-installed="1">English (United States)</option>';
    896904        foreach ( $languages as $language ) {
    897                 $selected = selected( $language['language'], $args['selected'], false );
    898                 printf(
    899                         '<option value="%s" lang="%s"%s>%s</option>',
     905                $structure[] = sprintf(
     906                        '<option value="%s" lang="%s"%s data-installed="1">%s</option>',
    900907                        esc_attr( $language['language'] ),
    901908                        esc_attr( $language['lang'] ),
    902                         $selected,
     909                        selected( $language['language'], $args['selected'], false ),
    903910                        esc_html( $language['native_name'] )
    904911                );
    905912        }
     913        $structure[] = '</optgroup>';
    906914
     915        // List available translations.
     916        if ( ! empty( $translations ) && $args['show_available_translations'] ) {
     917                $structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">';
     918                foreach ( $translations as $translation ) {
     919                        $structure[] = sprintf(
     920                                '<option value="%s" lang="%s"%s>%s</option>',
     921                                esc_attr( $translation['language'] ),
     922                                esc_attr( $translation['iso'][1] ),
     923                                selected( $translation['language'], $args['selected'], false ),
     924                                esc_html( $translation['native_name'] )
     925                        );
     926                }
     927                $structure[] = '</optgroup>';
     928        }
     929
     930        echo join( "\n", $structure );
     931
    907932        echo '</select>';
    908933}