Make WordPress Core

Ticket #48776: 48776.1.patch

File 48776.1.patch, 3.0 KB (added by sathyapulse, 5 years ago)

The patch addresses the problem in the server side and refactors the existing code to remove duplicates.

  • src/wp-admin/includes/translation-install.php

     
    148148}
    149149
    150150/**
     151 * Output the option for the language on the installation screen.
     152 *
     153 * @param array[] $language Array of language attributes.
     154 */
     155function wp_install_print_language_option( $language ) {
     156        $installed_languages = get_available_languages();
     157        $language_strings_continue = ! empty( $language['strings']['continue'] ) ? $language['strings']['continue'] : 'Continue';
     158        $is_language_installed = in_array( $language['language'], $installed_languages, true );
     159
     160        printf(
     161                '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
     162                esc_attr( $language['language'] ),
     163                esc_attr( current( $language['iso'] ) ),
     164                esc_attr( $language_strings_continue ),
     165                $is_language_installed ? ' data-installed="1"' : '',
     166                esc_html( $language['native_name'] )
     167        );
     168}
     169
     170/**
    151171 * Output the select form for the language selection on the installation screen.
    152172 *
    153173 * @since 4.0.0
     
    159179function wp_install_language_form( $languages ) {
    160180        global $wp_local_package;
    161181
    162         $installed_languages = get_available_languages();
    163 
    164182        echo "<label class='screen-reader-text' for='language'>Select a default language</label>\n";
    165183        echo "<select size='14' name='language' id='language'>\n";
    166184        echo '<option value="" lang="en" selected="selected" data-continue="Continue" data-installed="1">English (United States)</option>';
     
    167185        echo "\n";
    168186
    169187        if ( ! empty( $wp_local_package ) && isset( $languages[ $wp_local_package ] ) ) {
    170                 if ( isset( $languages[ $wp_local_package ] ) ) {
    171                         $language = $languages[ $wp_local_package ];
    172                         printf(
    173                                 '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
    174                                 esc_attr( $language['language'] ),
    175                                 esc_attr( current( $language['iso'] ) ),
    176                                 esc_attr( $language['strings']['continue'] ),
    177                                 in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
    178                                 esc_html( $language['native_name'] )
    179                         );
    180 
    181                         unset( $languages[ $wp_local_package ] );
    182                 }
     188                $language = $languages[ $wp_local_package ];
     189                wp_install_print_language_option( $language );
     190                unset( $languages[ $wp_local_package ] );
    183191        }
    184192
    185193        foreach ( $languages as $language ) {
    186                 printf(
    187                         '<option value="%s" lang="%s" data-continue="%s"%s>%s</option>' . "\n",
    188                         esc_attr( $language['language'] ),
    189                         esc_attr( current( $language['iso'] ) ),
    190                         esc_attr( $language['strings']['continue'] ),
    191                         in_array( $language['language'], $installed_languages ) ? ' data-installed="1"' : '',
    192                         esc_html( $language['native_name'] )
    193                 );
     194                wp_install_print_language_option( $language );
    194195        }
    195196        echo "</select>\n";
    196197        echo '<p class="step"><span class="spinner"></span><input id="language-continue" type="submit" class="button button-primary button-large" value="Continue" /></p>';