Make WordPress Core

Changeset 55099


Ignore:
Timestamp:
01/19/2023 02:11:08 PM (2 years ago)
Author:
swissspidy
Message:

I18N: Allow installing new translations when changing the user locale on the profile page.

Up until now, new translations could only be installed via Settings -> General.
When editing the user profile, one could only select locales that were already installed.

This change allows also installing new translations if the editing user has the necessary capabilities.

Props barryceelen, johnbillion, ocean90, swissspidy.
Fixes #38664.

Location:
trunk/src/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/css/forms.css

    r54185 r55099  
    10701070
    10711071.settings-php .language-install-spinner,
    1072 .options-general-php .language-install-spinner {
     1072.options-general-php .language-install-spinner,
     1073.user-edit-php .language-install-spinner,
     1074.profile-php .language-install-spinner {
    10731075    display: inline-block;
    10741076    float: none;
  • trunk/src/wp-admin/includes/user.php

    r54891 r55099  
    120120            $locale = 'en_US';
    121121        } elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
    122             $locale = '';
     122            if ( current_user_can( 'install_languages' ) && wp_can_install_language_pack() ) {
     123                if ( ! wp_download_language_pack( $locale ) ) {
     124                    $locale = '';
     125                }
     126            } else {
     127                $locale = '';
     128            }
    123129        }
    124130
  • trunk/src/wp-admin/user-edit.php

    r55096 r55099  
    99/** WordPress Administration Bootstrap */
    1010require_once __DIR__ . '/admin.php';
     11
     12/** WordPress Translation Installation API */
     13require_once ABSPATH . 'wp-admin/includes/translation-install.php';
    1114
    1215wp_reset_vars( array( 'action', 'user_id', 'wp_http_referer' ) );
     
    346349                    </tr>
    347350
    348                     <?php $languages = get_available_languages(); ?>
    349                     <?php if ( $languages ) : ?>
     351                    <?php
     352                    $languages = get_available_languages();
     353                    $can_install_translations = current_user_can( 'install_languages' ) && wp_can_install_language_pack();
     354                    ?>
     355                    <?php if ( $languages || $can_install_translations ) : ?>
    350356                    <tr class="user-language-wrap">
    351357                        <th scope="row">
     
    365371                            wp_dropdown_languages(
    366372                                array(
    367                                     'name'      => 'locale',
    368                                     'id'        => 'locale',
    369                                     'selected'  => $user_locale,
    370                                     'languages' => $languages,
    371                                     'show_available_translations' => false,
    372                                     'show_option_site_default' => true,
     373                                    'name'                        => 'locale',
     374                                    'id'                          => 'locale',
     375                                    'selected'                    => $user_locale,
     376                                    'languages'                   => $languages,
     377                                    'show_available_translations' => $can_install_translations,
     378                                    'show_option_site_default'    => true,
    373379                                )
    374380                            );
     
    912918</script>
    913919
     920<script type="text/javascript">
     921    jQuery( function( $ ) {
     922        var languageSelect = $( '#locale' );
     923        $( 'form' ).on( 'submit', function() {
     924            // Don't show a spinner for English and installed languages,
     925            // as there is nothing to download.
     926            if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
     927                $( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
     928            }
     929        });
     930    } );
     931</script>
     932
    914933<?php if ( isset( $application_passwords_list_table ) ) : ?>
    915934    <script type="text/html" id="tmpl-new-application-password">
Note: See TracChangeset for help on using the changeset viewer.