From 157a23382d316d2b735962d5be3b9bff4e297144 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 19 Jan 2023 14:11:08 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@55099 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/forms.css | 4 +++- src/wp-admin/includes/user.php | 8 +++++++- src/wp-admin/user-edit.php | 35 ++++++++++++++++++++++++++-------- 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/wp-admin/css/forms.css b/src/wp-admin/css/forms.css index 9066f58398..40c5e0903e 100644 --- a/src/wp-admin/css/forms.css +++ b/src/wp-admin/css/forms.css @@ -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; diff --git a/src/wp-admin/includes/user.php b/src/wp-admin/includes/user.php index 1df2739d48..5b6c6ffd8b 100644 --- a/src/wp-admin/includes/user.php +++ b/src/wp-admin/includes/user.php @@ -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; diff --git a/src/wp-admin/user-edit.php b/src/wp-admin/user-edit.php index 85ce99c4f7..2401a94d69 100644 --- a/src/wp-admin/user-edit.php +++ b/src/wp-admin/user-edit.php @@ -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 ) { - - + + @@ -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 ) { } + +