Make WordPress Core

Ticket #40829: 40829.diff

File 40829.diff, 4.9 KB (added by johnjamesjacoby, 8 years ago)
  • src/wp-includes/l10n.php

    diff --git src/wp-includes/l10n.php src/wp-includes/l10n.php
    index c5e460a..db286fd 100644
     
    11161116 * @param string|array $args {
    11171117 *     Optional. Array or string of arguments for outputting the language selector.
    11181118 *
    1119  *     @type string   $id                           ID attribute of the select element. Default empty.
    1120  *     @type string   $name                         Name attribute of the select element. Default empty.
     1119 *     @type string   $id                           ID attribute of the select element. Default 'locale'.
     1120 *     @type string   $name                         Name attribute of the select element. Default 'locale'.
    11211121 *     @type array    $languages                    List of installed languages, contain only the locales.
    11221122 *                                                  Default empty array.
    11231123 *     @type array    $translations                 List of available translations. Default result of
     
    11321132 */
    11331133function wp_dropdown_languages( $args = array() ) {
    11341134
    1135         $args = wp_parse_args( $args, array(
    1136                 'id'           => '',
    1137                 'name'         => '',
     1135        $r = wp_parse_args( $args, array(
     1136                'id'           => 'locale',
     1137                'name'         => 'locale',
    11381138                'languages'    => array(),
    11391139                'translations' => array(),
    11401140                'selected'     => '',
     
    11431143                'show_option_site_default'    => false,
    11441144        ) );
    11451145
    1146         // English (United States) uses an empty string for the value attribute.
    1147         if ( 'en_US' === $args['selected'] ) {
    1148                 $args['selected'] = '';
     1146        // Bail if no ID or no name.
     1147        if ( empty( $r['id'] ) || empty( $r['name'] ) ) {
     1148                return;
    11491149        }
    11501150
    1151         $translations = $args['translations'];
     1151        // English (United States) uses an empty string for the value attribute.
     1152        if ( 'en_US' === $r['selected'] ) {
     1153                $r['selected'] = '';
     1154        }
     1155
     1156        $translations = $r['translations'];
    11521157        if ( empty( $translations ) ) {
    11531158                require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
    11541159                $translations = wp_get_available_translations();
    11551160        }
    11561161
    11571162        /*
    1158          * $args['languages'] should only contain the locales. Find the locale in
     1163         * $r['languages'] should only contain the locales. Find the locale in
    11591164         * $translations to get the native name. Fall back to locale.
    11601165         */
    11611166        $languages = array();
    1162         foreach ( $args['languages'] as $locale ) {
     1167        foreach ( $r['languages'] as $locale ) {
    11631168                if ( isset( $translations[ $locale ] ) ) {
    11641169                        $translation = $translations[ $locale ];
    11651170                        $languages[] = array(
     
    11791184                }
    11801185        }
    11811186
    1182         $translations_available = ( ! empty( $translations ) && $args['show_available_translations'] );
    1183 
    1184         $output = sprintf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
     1187        $translations_available = ( ! empty( $translations ) && $r['show_available_translations'] );
    11851188
    11861189        // Holds the HTML markup.
    11871190        $structure = array();
     
    11911194                $structure[] = '<optgroup label="' . esc_attr_x( 'Installed', 'translations' ) . '">';
    11921195        }
    11931196
    1194         if ( $args['show_option_site_default'] ) {
     1197        // Site default.
     1198        if ( $r['show_option_site_default'] ) {
    11951199                $structure[] = sprintf(
    11961200                        '<option value="site-default" data-installed="1"%s>%s</option>',
    1197                         selected( 'site-default', $args['selected'], false ),
     1201                        selected( 'site-default', $r['selected'], false ),
    11981202                        _x( 'Site Default', 'default site language' )
    11991203                );
    12001204        }
    12011205
     1206        // Always show English.
    12021207        $structure[] = sprintf(
    12031208                '<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
    1204                 selected( '', $args['selected'], false )
     1209                selected( '', $r['selected'], false )
    12051210        );
    12061211
     1212        // List installed languages.
    12071213        foreach ( $languages as $language ) {
    12081214                $structure[] = sprintf(
    12091215                        '<option value="%s" lang="%s"%s data-installed="1">%s</option>',
    12101216                        esc_attr( $language['language'] ),
    12111217                        esc_attr( $language['lang'] ),
    1212                         selected( $language['language'], $args['selected'], false ),
     1218                        selected( $language['language'], $r['selected'], false ),
    12131219                        esc_html( $language['native_name'] )
    12141220                );
    12151221        }
     1222
    12161223        if ( $translations_available ) {
    12171224                $structure[] = '</optgroup>';
    1218         }
    12191225
    1220         // List available translations.
    1221         if ( $translations_available ) {
     1226                // List available translations.
    12221227                $structure[] = '<optgroup label="' . esc_attr_x( 'Available', 'translations' ) . '">';
    12231228                foreach ( $translations as $translation ) {
    12241229                        $structure[] = sprintf(
    12251230                                '<option value="%s" lang="%s"%s>%s</option>',
    12261231                                esc_attr( $translation['language'] ),
    12271232                                esc_attr( current( $translation['iso'] ) ),
    1228                                 selected( $translation['language'], $args['selected'], false ),
     1233                                selected( $translation['language'], $r['selected'], false ),
    12291234                                esc_html( $translation['native_name'] )
    12301235                        );
    12311236                }
    12321237                $structure[] = '</optgroup>';
    12331238        }
    12341239
     1240        // Combine the output string.
     1241        $output  = sprintf( '<select name="%s" id="%s">', esc_attr( $r['name'] ), esc_attr( $r['id'] ) );
    12351242        $output .= join( "\n", $structure );
    1236 
    12371243        $output .= '</select>';
    12381244
    1239         if ( $args['echo'] ) {
     1245        if ( $r['echo'] ) {
    12401246                echo $output;
    12411247        }
    12421248