Make WordPress Core


Ignore:
Timestamp:
11/03/2026 01:38:37 PM (9 days ago)
Author:
audrasjb
Message:

Upgrade/Install: Show and allow to select translation updates on the Updates screen.

This changeset introduces a way to see each available translation update on the Updates screen, and allows users to update them selectively. With this change, translation updates management is more consistent with how plugin and theme updates are managed.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/11610.

Props stk_jj, Presskopp, jyria, tfrommen, audrasjb, ozgursar, im3dabasia1.
Fixes #42281.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/update-core.php

    r61520 r65226  
    814814 */
    815815function list_translation_updates() {
    816         $updates = wp_get_translation_updates();
    817         if ( ! $updates ) {
     816        $translation_updates = wp_get_translation_update_data();
     817        if ( ! $translation_updates ) {
    818818                if ( 'en_US' !== get_locale() ) {
    819819                        echo '<h2>' . __( 'Translations' ) . '</h2>';
    … …  
    823823        }
    824824
    825         $form_action = 'update-core.php?action=do-translation-upgrade';
     825        $form_action   = 'update-core.php?action=do-translation-upgrade';
     826        $updates_count = count( $translation_updates );
    826827        ?>
    827         <h2><?php _e( 'Translations' ); ?></h2>
     828        <h2>
     829        <?php
     830        printf(
     831                '%s <span class="count">(%s)</span>',
     832                __( 'Translations' ),
     833                number_format_i18n( $updates_count )
     834        );
     835        ?>
     836        </h2>
    828837        <form method="post" action="<?php echo esc_url( $form_action ); ?>" name="upgrade-translations" class="upgrade">
    829                 <p><?php _e( 'New translations are available.' ); ?></p>
     838                <p><?php _e( 'The following translation updates are available. Leave any translation updates unchecked if you want to install them later, then click &#8220;Update Translations&#8221;.' ); ?></p>
     839                <p><?php _e( 'Translation updates you leave unchecked will remain available until you select them.' ); ?></p>
    830840                <?php wp_nonce_field( 'upgrade-translations' ); ?>
    831                 <p><input class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
     841                <p><input id="upgrade-translations" class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
     842                <table class="widefat updates-table" id="update-translations-table">
     843                        <thead>
     844                        <tr>
     845                                <td class="manage-column check-column"><input type="checkbox" id="translations-select-all" /></td>
     846                                <td class="manage-column"><label for="translations-select-all"><?php _e( 'Select All' ); ?></label></td>
     847                        </tr>
     848                        </thead>
     849
     850                        <tbody class="plugins">
     851                        <?php foreach ( $translation_updates as $translation_update ) : ?>
     852                                <?php $checkbox_id = 'checkbox_' . md5( $translation_update['id'] ); ?>
     853                                <tr>
     854                                        <td class="check-column">
     855                                                <input type="hidden" name="translations[]" value="<?php echo esc_attr( $translation_update['id'] ); ?>" />
     856                                                <input type="checkbox" name="checked[]" id="<?php echo esc_attr( $checkbox_id ); ?>" value="<?php echo esc_attr( $translation_update['id'] ); ?>" <?php checked( $translation_update['checked'] ); ?> />
     857                                                <label for="<?php echo esc_attr( $checkbox_id ); ?>">
     858                                                        <span class="screen-reader-text">
     859                                                        <?php
     860                                                        printf(
     861                                                                /* translators: 1: Project name, 2: Language name or locale. */
     862                                                                esc_html__( 'Select the translation update for %1$s in %2$s' ),
     863                                                                esc_html( $translation_update['name'] ),
     864                                                                esc_html( $translation_update['language'] )
     865                                                        );
     866                                                        ?>
     867                                                        </span>
     868                                                </label>
     869                                        </td>
     870                                        <td class="plugin-title"><p>
     871                                                <strong><?php echo esc_html( $translation_update['name'] ); ?></strong>
     872                                                <?php
     873                                                printf(
     874                                                        /* translators: 1: Language name or locale, 2: Version number. */
     875                                                        esc_html__( '%1$s translation is available for version %2$s.' ),
     876                                                        esc_html( $translation_update['language'] ),
     877                                                        esc_html( $translation_update['version'] )
     878                                                );
     879
     880                                                if ( $translation_update['deferred'] ) {
     881                                                        echo ' ';
     882                                                        esc_html_e( 'This translation update will remain available until you select it.' );
     883                                                }
     884                                                ?>
     885                                        </p></td>
     886                                </tr>
     887                        <?php endforeach; ?>
     888                        </tbody>
     889
     890                        <tfoot>
     891                        <tr>
     892                                <td class="manage-column check-column"><input type="checkbox" id="translations-select-all-2" /></td>
     893                                <td class="manage-column"><label for="translations-select-all-2"><?php _e( 'Select All' ); ?></label></td>
     894                        </tr>
     895                        </tfoot>
     896                </table>
     897                <p><input id="upgrade-translations-2" class="button" type="submit" value="<?php esc_attr_e( 'Update Translations' ); ?>" name="upgrade" /></p>
    832898        </form>
    833899        <?php
    … …  
    10031069
    10041070if ( 'en_US' !== get_locale() ) {
    1005         $updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; The files translating WordPress into your language are updated for you whenever any other updates occur. But if these files are out of date, you can <strong>click the &#8220;Update Translations&#8221;</strong> button.' ) . '</p>';
     1071        $updates_howto .= '<p>' . __( '<strong>Translations</strong> &mdash; Translation updates are selected for installation by default. Leave any translation updates unchecked if you want to install them later, then <strong>click the &#8220;Update Translations&#8221;</strong> button. Translation updates you leave unchecked will remain available until you select them.' ) . '</p>';
    10061072}
    10071073
    … …  
    10931159        }
    10941160
     1161        $translation_updates_status = isset( $_GET['translation_updates'] ) ? wp_unslash( $_GET['translation_updates'] ) : '';
     1162        if ( is_string( $translation_updates_status ) ) {
     1163                $translation_updates_status = sanitize_key( $translation_updates_status );
     1164        } else {
     1165                $translation_updates_status = '';
     1166        }
     1167
     1168        if ( 'deferred' === $translation_updates_status ) {
     1169                wp_admin_notice(
     1170                        __( 'The unchecked translation updates will remain available until you select them.' ),
     1171                        array(
     1172                                'type' => 'success',
     1173                        )
     1174                );
     1175        }
     1176
    10951177        $last_update_check = false;
    10961178        $current           = get_site_transient( 'update_core' );
    … …  
    12761358        check_admin_referer( 'upgrade-translations' );
    12771359
     1360        // Requests without the form's update identifiers must not install all translations.
     1361        $translation_update_ids          = array_unique(
     1362                array_map(
     1363                        'sanitize_text_field',
     1364                        wp_unslash( (array) ( $_POST['translations'] ?? array() ) )
     1365                )
     1366        );
     1367        $selected_translation_update_ids = array_unique(
     1368                array_map(
     1369                        'sanitize_text_field',
     1370                        wp_unslash( (array) ( $_POST['checked'] ?? array() ) )
     1371                )
     1372        );
     1373
     1374        $selected_translation_updates = wp_process_translation_update_selection( $translation_update_ids, $selected_translation_update_ids );
     1375
     1376        if ( false === $selected_translation_updates ) {
     1377                wp_redirect( self_admin_url( 'update-core.php' ) );
     1378                exit;
     1379        }
     1380
     1381        if ( empty( $selected_translation_updates ) ) {
     1382                wp_redirect( add_query_arg( 'translation_updates', 'deferred', self_admin_url( 'update-core.php' ) ) );
     1383                exit;
     1384        }
     1385
    12781386        require_once ABSPATH . 'wp-admin/admin-header.php';
    12791387        require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
    … …  
    12851393
    12861394        $upgrader = new Language_Pack_Upgrader( new Language_Pack_Upgrader_Skin( compact( 'url', 'nonce', 'title', 'context' ) ) );
    1287         $result   = $upgrader->bulk_upgrade();
     1395        $result   = $upgrader->bulk_upgrade( array_values( $selected_translation_updates ) );
    12881396
    12891397        wp_localize_script(
Note: See TracChangeset for help on using the changeset viewer.