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.
Built from https://develop.svn.wordpress.org/trunk@55099


git-svn-id: http://core.svn.wordpress.org/trunk@54632 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2023-01-19 14:13:13 +00:00
parent ff7751868f
commit 58545bacce
7 changed files with 43 additions and 14 deletions

View File

@ -1070,7 +1070,9 @@ table.form-table td .updated p {
}
.settings-php .language-install-spinner,
.options-general-php .language-install-spinner {
.options-general-php .language-install-spinner,
.user-edit-php .language-install-spinner,
.profile-php .language-install-spinner {
display: inline-block;
float: none;
margin: -3px 5px 0;

File diff suppressed because one or more lines are too long

View File

@ -1069,7 +1069,9 @@ table.form-table td .updated p {
}
.settings-php .language-install-spinner,
.options-general-php .language-install-spinner {
.options-general-php .language-install-spinner,
.user-edit-php .language-install-spinner,
.profile-php .language-install-spinner {
display: inline-block;
float: none;
margin: -3px 5px 0;

File diff suppressed because one or more lines are too long

View File

@ -119,7 +119,13 @@ function edit_user( $user_id = 0 ) {
} elseif ( '' === $locale ) {
$locale = 'en_US';
} elseif ( ! in_array( $locale, get_available_languages(), true ) ) {
$locale = '';
if ( current_user_can( 'install_languages' ) && wp_can_install_language_pack() ) {
if ( ! wp_download_language_pack( $locale ) ) {
$locale = '';
}
} else {
$locale = '';
}
}
$user->locale = $locale;

View File

@ -9,6 +9,9 @@
/** WordPress Administration Bootstrap */
require_once __DIR__ . '/admin.php';
/** WordPress Translation Installation API */
require_once ABSPATH . 'wp-admin/includes/translation-install.php';
wp_reset_vars( array( 'action', 'user_id', 'wp_http_referer' ) );
$user_id = (int) $user_id;
@ -345,8 +348,11 @@ switch ( $action ) {
</td>
</tr>
<?php $languages = get_available_languages(); ?>
<?php if ( $languages ) : ?>
<?php
$languages = get_available_languages();
$can_install_translations = current_user_can( 'install_languages' ) && wp_can_install_language_pack();
?>
<?php if ( $languages || $can_install_translations ) : ?>
<tr class="user-language-wrap">
<th scope="row">
<?php /* translators: The user language selection field label. */ ?>
@ -364,12 +370,12 @@ switch ( $action ) {
wp_dropdown_languages(
array(
'name' => 'locale',
'id' => 'locale',
'selected' => $user_locale,
'languages' => $languages,
'show_available_translations' => false,
'show_option_site_default' => true,
'name' => 'locale',
'id' => 'locale',
'selected' => $user_locale,
'languages' => $languages,
'show_available_translations' => $can_install_translations,
'show_option_site_default' => true,
)
);
?>
@ -911,6 +917,19 @@ switch ( $action ) {
}
</script>
<script type="text/javascript">
jQuery( function( $ ) {
var languageSelect = $( '#locale' );
$( 'form' ).on( 'submit', function() {
// Don't show a spinner for English and installed languages,
// as there is nothing to download.
if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
}
});
} );
</script>
<?php if ( isset( $application_passwords_list_table ) ) : ?>
<script type="text/html" id="tmpl-new-application-password">
<div class="notice notice-success is-dismissible new-application-password-notice" role="alert" tabindex="-1">

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.2-alpha-55098';
$wp_version = '6.2-alpha-55099';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.