I18N: Use `wp.i18n` for translatable strings in `wp-admin/js/updates.js`.

This removes the usage of `wp_localize_script()` for passing translations to the script and instead adds the translatable strings in the script directly through the use of `wp.i18n` and its utilities.

Props swissspidy, ocean90.
See #20491.
Fixes #50235.
Built from https://develop.svn.wordpress.org/trunk@47884


git-svn-id: http://core.svn.wordpress.org/trunk@47658 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2020-06-01 21:41:09 +00:00
parent 0318a92948
commit ba92ed7615
5 changed files with 325 additions and 204 deletions

View File

@ -799,7 +799,7 @@ themes.view.Details = wp.Backbone.View.extend({
_this.model.set( { autoupdate: 'enable' === data.state } ); _this.model.set( { autoupdate: 'enable' === data.state } );
$( document ).off( 'wp-auto-update-setting-changed', callback ); $( document ).off( 'wp-auto-update-setting-changed', callback );
} }
} };
// Triggered in updates.js // Triggered in updates.js
$( document ).on( 'wp-auto-update-setting-changed', callback ); $( document ).on( 'wp-auto-update-setting-changed', callback );

View File

@ -12,7 +12,6 @@
* @param {object} wp WP object. * @param {object} wp WP object.
* @param {object} settings WP Updates settings. * @param {object} settings WP Updates settings.
* @param {string} settings.ajax_nonce AJAX nonce. * @param {string} settings.ajax_nonce AJAX nonce.
* @param {object} settings.l10n Translation strings.
* @param {object=} settings.plugins Base names of plugins in their different states. * @param {object=} settings.plugins Base names of plugins in their different states.
* @param {Array} settings.plugins.all Base names of all plugins. * @param {Array} settings.plugins.all Base names of all plugins.
* @param {Array} settings.plugins.active Base names of active plugins. * @param {Array} settings.plugins.active Base names of active plugins.
@ -27,7 +26,10 @@
* @param {number} settings.totals.count Holds the amount of available updates. * @param {number} settings.totals.count Holds the amount of available updates.
*/ */
(function( $, wp, settings ) { (function( $, wp, settings ) {
var $document = $( document ); var $document = $( document ),
__ = wp.i18n.__,
_x = wp.i18n._x,
sprintf = wp.i18n.sprintf;
wp = wp || {}; wp = wp || {};
@ -49,15 +51,6 @@
*/ */
wp.updates.ajaxNonce = settings.ajax_nonce; wp.updates.ajaxNonce = settings.ajax_nonce;
/**
* Localized strings.
*
* @since 4.2.0
*
* @type {object}
*/
wp.updates.l10n = settings.l10n;
/** /**
* Current search term. * Current search term.
* *
@ -381,23 +374,31 @@
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
$updateRow = $( 'tr[data-plugin="' + args.plugin + '"]' ); $updateRow = $( 'tr[data-plugin="' + args.plugin + '"]' );
$message = $updateRow.find( '.update-message' ).removeClass( 'notice-error' ).addClass( 'updating-message notice-warning' ).find( 'p' ); $message = $updateRow.find( '.update-message' ).removeClass( 'notice-error' ).addClass( 'updating-message notice-warning' ).find( 'p' );
message = wp.updates.l10n.pluginUpdatingLabel.replace( '%s', $updateRow.find( '.plugin-title strong' ).text() ); message = sprintf(
/* translators: %s: Plugin name and version. */
_x( 'Updating %s...', 'plugin' ),
$updateRow.find( '.plugin-title strong' ).text()
);
} else if ( 'plugin-install' === pagenow || 'plugin-install-network' === pagenow ) { } else if ( 'plugin-install' === pagenow || 'plugin-install-network' === pagenow ) {
$card = $( '.plugin-card-' + args.slug ); $card = $( '.plugin-card-' + args.slug );
$message = $card.find( '.update-now' ).addClass( 'updating-message' ); $message = $card.find( '.update-now' ).addClass( 'updating-message' );
message = wp.updates.l10n.pluginUpdatingLabel.replace( '%s', $message.data( 'name' ) ); message = sprintf(
/* translators: %s: Plugin name and version. */
_x( 'Updating %s...', 'plugin' ),
$message.data( 'name' )
);
// Remove previous error messages, if any. // Remove previous error messages, if any.
$card.removeClass( 'plugin-card-update-failed' ).find( '.notice.notice-error' ).remove(); $card.removeClass( 'plugin-card-update-failed' ).find( '.notice.notice-error' ).remove();
} }
if ( $message.html() !== wp.updates.l10n.updating ) { if ( $message.html() !== __( 'Updating...' ) ) {
$message.data( 'originaltext', $message.html() ); $message.data( 'originaltext', $message.html() );
} }
$message $message
.attr( 'aria-label', message ) .attr( 'aria-label', message )
.text( wp.updates.l10n.updating ); .text( __( 'Updating...' ) );
$document.trigger( 'wp-plugin-updating', args ); $document.trigger( 'wp-plugin-updating', args );
@ -442,10 +443,17 @@
} }
$updateMessage $updateMessage
.attr( 'aria-label', wp.updates.l10n.pluginUpdatedLabel.replace( '%s', response.pluginName ) ) .attr(
.text( wp.updates.l10n.pluginUpdated ); 'aria-label',
sprintf(
/* translators: %s: Plugin name and version. */
_x( '%s updated!', 'plugin' ),
response.pluginName
)
)
.text( _x( 'Updated!', 'plugin' ) );
wp.a11y.speak( wp.updates.l10n.updatedMsg, 'polite' ); wp.a11y.speak( __( 'Update completed successfully.' ), 'polite' );
wp.updates.decrementCount( 'plugin' ); wp.updates.decrementCount( 'plugin' );
@ -476,7 +484,11 @@
return; return;
} }
errorMessage = wp.updates.l10n.updateFailed.replace( '%s', response.errorMessage ); errorMessage = sprintf(
/* translators: %s: Error string for a failed update. */
__( 'Update Failed: %s' ),
response.errorMessage
);
if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) {
if ( response.plugin ) { if ( response.plugin ) {
@ -488,7 +500,14 @@
if ( response.pluginName ) { if ( response.pluginName ) {
$message.find( 'p' ) $message.find( 'p' )
.attr( 'aria-label', wp.updates.l10n.pluginUpdateFailedLabel.replace( '%s', response.pluginName ) ); .attr(
'aria-label',
sprintf(
/* translators: %s: Plugin name and version. */
_x( '%s update failed', 'plugin' ),
response.pluginName
)
);
} else { } else {
$message.find( 'p' ).removeAttr( 'aria-label' ); $message.find( 'p' ).removeAttr( 'aria-label' );
} }
@ -501,11 +520,19 @@
} ) ); } ) );
$card.find( '.update-now' ) $card.find( '.update-now' )
.text( wp.updates.l10n.updateFailedShort ).removeClass( 'updating-message' ); .text( __( 'Update Failed!' ) )
.removeClass( 'updating-message' );
if ( response.pluginName ) { if ( response.pluginName ) {
$card.find( '.update-now' ) $card.find( '.update-now' )
.attr( 'aria-label', wp.updates.l10n.pluginUpdateFailedLabel.replace( '%s', response.pluginName ) ); .attr(
'aria-label',
sprintf(
/* translators: %s: Plugin name and version. */
_x( '%s update failed', 'plugin' ),
response.pluginName
)
);
} else { } else {
$card.find( '.update-now' ).removeAttr( 'aria-label' ); $card.find( '.update-now' ).removeAttr( 'aria-label' );
} }
@ -520,7 +547,7 @@
$card.find( '.update-now' ) $card.find( '.update-now' )
.attr( 'aria-label', false ) .attr( 'aria-label', false )
.text( wp.updates.l10n.updateNow ); .text( __( 'Update Now' ) );
}, 200 ); }, 200 );
} ); } );
} }
@ -555,16 +582,23 @@
$message = $( '[data-slug="' + args.slug + '"]' ); $message = $( '[data-slug="' + args.slug + '"]' );
} }
if ( $message.html() !== wp.updates.l10n.installing ) { if ( $message.html() !== __( 'Installing...' ) ) {
$message.data( 'originaltext', $message.html() ); $message.data( 'originaltext', $message.html() );
} }
$message $message
.addClass( 'updating-message' ) .addClass( 'updating-message' )
.attr( 'aria-label', wp.updates.l10n.pluginInstallingLabel.replace( '%s', $message.data( 'name' ) ) ) .attr(
.text( wp.updates.l10n.installing ); 'aria-label',
sprintf(
/* translators: %s: Plugin name and version. */
_x( 'Installing %s...', 'plugin' ),
$message.data( 'name' )
)
)
.text( __( 'Installing...' ) );
wp.a11y.speak( wp.updates.l10n.installingMsg, 'polite' ); wp.a11y.speak( __( 'Installing... please wait.' ), 'polite' );
// Remove previous error messages, if any. // Remove previous error messages, if any.
$card.removeClass( 'plugin-card-install-failed' ).find( '.notice.notice-error' ).remove(); $card.removeClass( 'plugin-card-install-failed' ).find( '.notice.notice-error' ).remove();
@ -590,10 +624,17 @@
$message $message
.removeClass( 'updating-message' ) .removeClass( 'updating-message' )
.addClass( 'updated-message installed button-disabled' ) .addClass( 'updated-message installed button-disabled' )
.attr( 'aria-label', wp.updates.l10n.pluginInstalledLabel.replace( '%s', response.pluginName ) ) .attr(
.text( wp.updates.l10n.pluginInstalled ); 'aria-label',
sprintf(
/* translators: %s: Plugin name and version. */
_x( '%s installed!', 'plugin' ),
response.pluginName
)
)
.text( _x( 'Installed!', 'plugin' ) );
wp.a11y.speak( wp.updates.l10n.installedMsg, 'polite' ); wp.a11y.speak( __( 'Installation completed successfully.' ), 'polite' );
$document.trigger( 'wp-plugin-install-success', response ); $document.trigger( 'wp-plugin-install-success', response );
@ -601,10 +642,33 @@
setTimeout( function() { setTimeout( function() {
// Transform the 'Install' button into an 'Activate' button. // Transform the 'Install' button into an 'Activate' button.
$message.removeClass( 'install-now installed button-disabled updated-message' ).addClass( 'activate-now button-primary' ) $message.removeClass( 'install-now installed button-disabled updated-message' )
.attr( 'href', response.activateUrl ) .addClass( 'activate-now button-primary' )
.attr( 'aria-label', wp.updates.l10n.activatePluginLabel.replace( '%s', response.pluginName ) ) .attr( 'href', response.activateUrl );
.text( wp.updates.l10n.activatePlugin );
if ( 'plugins-network' === pagenow ) {
$message
.attr(
'aria-label',
sprintf(
/* translators: %s: Plugin name. */
_x( 'Network Activate %s', 'plugin' ),
response.pluginName
)
)
.text( __( 'Network Activate' ) );
} else {
$message
.attr(
'aria-label',
sprintf(
/* translators: %s: Plugin name. */
_x( 'Activate %s', 'plugin' ),
response.pluginName
)
)
.text( __( 'Activate' ) );
}
}, 1000 ); }, 1000 );
} }
}; };
@ -633,7 +697,11 @@
return; return;
} }
errorMessage = wp.updates.l10n.installFailed.replace( '%s', response.errorMessage ); errorMessage = sprintf(
/* translators: %s: Error string for a failed installation. */
__( 'Installation failed: %s' ),
response.errorMessage
);
$card $card
.addClass( 'plugin-card-update-failed' ) .addClass( 'plugin-card-update-failed' )
@ -651,8 +719,15 @@
$button $button
.removeClass( 'updating-message' ).addClass( 'button-disabled' ) .removeClass( 'updating-message' ).addClass( 'button-disabled' )
.attr( 'aria-label', wp.updates.l10n.pluginInstallFailedLabel.replace( '%s', $button.data( 'name' ) ) ) .attr(
.text( wp.updates.l10n.installFailedShort ); 'aria-label',
sprintf(
/* translators: %s: Plugin name and version. */
_x( '%s installation failed', 'plugin' ),
$button.data( 'name' )
)
)
.text( __( 'Installation Failed!' ) );
wp.a11y.speak( errorMessage, 'assertive' ); wp.a11y.speak( errorMessage, 'assertive' );
@ -673,7 +748,11 @@
wp.updates.addAdminNotice( { wp.updates.addAdminNotice( {
id: 'install-success', id: 'install-success',
className: 'notice-success is-dismissible', className: 'notice-success is-dismissible',
message: wp.updates.l10n.importerInstalledMsg.replace( '%s', response.activateUrl + '&from=import' ) message: sprintf(
/* translators: %s: Activation URL. */
__( 'Importer installed successfully. <a href="%s">Run importer</a>' ),
response.activateUrl + '&from=import'
)
} ); } );
$( '[data-slug="' + response.slug + '"]' ) $( '[data-slug="' + response.slug + '"]' )
@ -681,11 +760,15 @@
.addClass( 'activate-now' ) .addClass( 'activate-now' )
.attr({ .attr({
'href': response.activateUrl + '&from=import', 'href': response.activateUrl + '&from=import',
'aria-label': wp.updates.l10n.activateImporterLabel.replace( '%s', response.pluginName ) 'aria-label':sprintf(
/* translators: %s: Importer name. */
__( 'Run %s' ),
response.pluginName
)
}) })
.text( wp.updates.l10n.activateImporter ); .text( __( 'Run Importer' ) );
wp.a11y.speak( wp.updates.l10n.installedMsg, 'polite' ); wp.a11y.speak( __( 'Installation completed successfully.' ), 'polite' );
$document.trigger( 'wp-importer-install-success', response ); $document.trigger( 'wp-importer-install-success', response );
}; };
@ -702,7 +785,11 @@
* @param {string} response.errorMessage The error that occurred. * @param {string} response.errorMessage The error that occurred.
*/ */
wp.updates.installImporterError = function( response ) { wp.updates.installImporterError = function( response ) {
var errorMessage = wp.updates.l10n.installFailed.replace( '%s', response.errorMessage ), var errorMessage = sprintf(
/* translators: %s: Error string for a failed installation. */
__( 'Installation failed: %s' ),
response.errorMessage
),
$installLink = $( '[data-slug="' + response.slug + '"]' ), $installLink = $( '[data-slug="' + response.slug + '"]' ),
pluginName = $installLink.data( 'name' ); pluginName = $installLink.data( 'name' );
@ -722,8 +809,15 @@
$installLink $installLink
.removeClass( 'updating-message' ) .removeClass( 'updating-message' )
.text( wp.updates.l10n.installNow ) .attr(
.attr( 'aria-label', wp.updates.l10n.pluginInstallNowLabel.replace( '%s', pluginName ) ); 'aria-label',
sprintf(
/* translators: %s: Plugin name. */
_x( 'Install %s now', 'plugin' ),
pluginName
)
)
.text( __( 'Install Now' ) );
wp.a11y.speak( errorMessage, 'assertive' ); wp.a11y.speak( errorMessage, 'assertive' );
@ -751,13 +845,13 @@
error: wp.updates.deletePluginError error: wp.updates.deletePluginError
}, args ); }, args );
if ( $link.html() !== wp.updates.l10n.deleting ) { if ( $link.html() !== __( 'Deleting...' ) ) {
$link $link
.data( 'originaltext', $link.html() ) .data( 'originaltext', $link.html() )
.text( wp.updates.l10n.deleting ); .text( __( 'Deleting...' ) );
} }
wp.a11y.speak( wp.updates.l10n.deleting, 'polite' ); wp.a11y.speak( __( 'Deleting...' ), 'polite' );
$document.trigger( 'wp-plugin-deleting', args ); $document.trigger( 'wp-plugin-deleting', args );
@ -847,12 +941,12 @@
$views.find( '.all' ).remove(); $views.find( '.all' ).remove();
if ( ! $form.find( 'tr.no-items' ).length ) { if ( ! $form.find( 'tr.no-items' ).length ) {
$form.find( '#the-list' ).append( '<tr class="no-items"><td class="colspanchange" colspan="' + columnCount + '">' + wp.updates.l10n.noPlugins + '</td></tr>' ); $form.find( '#the-list' ).append( '<tr class="no-items"><td class="colspanchange" colspan="' + columnCount + '">' + __( 'You do not appear to have any plugins available at this time.' ) + '</td></tr>' );
} }
} }
} ); } );
wp.a11y.speak( wp.updates.l10n.pluginDeleted, 'polite' ); wp.a11y.speak( _x( 'Deleted!', 'plugin' ), 'polite' );
$document.trigger( 'wp-plugin-delete-success', response ); $document.trigger( 'wp-plugin-delete-success', response );
}; };
@ -957,12 +1051,12 @@
$notice = $notice.addClass( 'updating-message' ).find( 'p' ); $notice = $notice.addClass( 'updating-message' ).find( 'p' );
} }
if ( $notice.html() !== wp.updates.l10n.updating ) { if ( $notice.html() !== __( 'Updating...' ) ) {
$notice.data( 'originaltext', $notice.html() ); $notice.data( 'originaltext', $notice.html() );
} }
wp.a11y.speak( wp.updates.l10n.updatingMsg, 'polite' ); wp.a11y.speak( __( 'Updating... please wait.' ), 'polite' );
$notice.text( wp.updates.l10n.updating ); $notice.text( __( 'Updating...' ) );
$document.trigger( 'wp-theme-updating', args ); $document.trigger( 'wp-theme-updating', args );
@ -986,7 +1080,7 @@
$theme = $( '[data-slug="' + response.slug + '"]' ), $theme = $( '[data-slug="' + response.slug + '"]' ),
updatedMessage = { updatedMessage = {
className: 'updated-message notice-success notice-alt', className: 'updated-message notice-success notice-alt',
message: wp.updates.l10n.themeUpdated message: _x( 'Updated!', 'theme' )
}, },
$notice, newText; $notice, newText;
@ -1023,7 +1117,7 @@
} }
wp.updates.addAdminNotice( _.extend( { selector: $notice }, updatedMessage ) ); wp.updates.addAdminNotice( _.extend( { selector: $notice }, updatedMessage ) );
wp.a11y.speak( wp.updates.l10n.updatedMsg, 'polite' ); wp.a11y.speak( __( 'Update completed successfully.' ), 'polite' );
wp.updates.decrementCount( 'theme' ); wp.updates.decrementCount( 'theme' );
@ -1047,7 +1141,11 @@
*/ */
wp.updates.updateThemeError = function( response ) { wp.updates.updateThemeError = function( response ) {
var $theme = $( '[data-slug="' + response.slug + '"]' ), var $theme = $( '[data-slug="' + response.slug + '"]' ),
errorMessage = wp.updates.l10n.updateFailed.replace( '%s', response.errorMessage ), errorMessage = sprintf(
/* translators: %s: Error string for a failed update. */
__( 'Update Failed: %s' ),
response.errorMessage
),
$notice; $notice;
if ( ! wp.updates.isValidResponse( response, 'update' ) ) { if ( ! wp.updates.isValidResponse( response, 'update' ) ) {
@ -1103,14 +1201,22 @@
$message.addClass( 'updating-message' ); $message.addClass( 'updating-message' );
$message.parents( '.theme' ).addClass( 'focus' ); $message.parents( '.theme' ).addClass( 'focus' );
if ( $message.html() !== wp.updates.l10n.installing ) { if ( $message.html() !== __( 'Installing...' ) ) {
$message.data( 'originaltext', $message.html() ); $message.data( 'originaltext', $message.html() );
} }
$message $message
.text( wp.updates.l10n.installing ) .attr(
.attr( 'aria-label', wp.updates.l10n.themeInstallingLabel.replace( '%s', $message.data( 'name' ) ) ); 'aria-label',
wp.a11y.speak( wp.updates.l10n.installingMsg, 'polite' ); sprintf(
/* translators: %s: Theme name and version. */
_x( 'Installing %s...', 'theme' ),
$message.data( 'name' )
)
)
.text( __( 'Installing...' ) );
wp.a11y.speak( __( 'Installing... please wait.' ), 'polite' );
// Remove previous error messages, if any. // Remove previous error messages, if any.
$( '.install-theme-info, [data-slug="' + args.slug + '"]' ).removeClass( 'theme-install-failed' ).find( '.notice.notice-error' ).remove(); $( '.install-theme-info, [data-slug="' + args.slug + '"]' ).removeClass( 'theme-install-failed' ).find( '.notice.notice-error' ).remove();
@ -1139,10 +1245,17 @@
$message = $card.find( '.button-primary' ) $message = $card.find( '.button-primary' )
.removeClass( 'updating-message' ) .removeClass( 'updating-message' )
.addClass( 'updated-message disabled' ) .addClass( 'updated-message disabled' )
.attr( 'aria-label', wp.updates.l10n.themeInstalledLabel.replace( '%s', response.themeName ) ) .attr(
.text( wp.updates.l10n.themeInstalled ); 'aria-label',
sprintf(
/* translators: %s: Theme name and version. */
_x( '%s installed!', 'theme' ),
response.themeName
)
)
.text( _x( 'Installed!', 'theme' ) );
wp.a11y.speak( wp.updates.l10n.installedMsg, 'polite' ); wp.a11y.speak( __( 'Installation completed successfully.' ), 'polite' );
setTimeout( function() { setTimeout( function() {
@ -1152,9 +1265,31 @@
$message $message
.attr( 'href', response.activateUrl ) .attr( 'href', response.activateUrl )
.removeClass( 'theme-install updated-message disabled' ) .removeClass( 'theme-install updated-message disabled' )
.addClass( 'activate' ) .addClass( 'activate' );
.attr( 'aria-label', wp.updates.l10n.activateThemeLabel.replace( '%s', response.themeName ) )
.text( wp.updates.l10n.activateTheme ); if ( 'themes-network' === pagenow ) {
$message
.attr(
'aria-label',
sprintf(
/* translators: %s: Theme name. */
_x( 'Network Activate %s', 'theme' ),
response.themeName
)
)
.text( __( 'Network Enable' ) );
} else {
$message
.attr(
'aria-label',
sprintf(
/* translators: %s: Theme name. */
_x( 'Activate %s', 'theme' ),
response.themeName
)
)
.text( __( 'Activate' ) );
}
} }
if ( response.customizeUrl ) { if ( response.customizeUrl ) {
@ -1164,7 +1299,7 @@
return $( '<a>' ) return $( '<a>' )
.attr( 'href', response.customizeUrl ) .attr( 'href', response.customizeUrl )
.addClass( 'button load-customize' ) .addClass( 'button load-customize' )
.text( wp.updates.l10n.livePreview ); .text( __( 'Live Preview' ) );
} ); } );
} }
}, 1000 ); }, 1000 );
@ -1182,7 +1317,11 @@
*/ */
wp.updates.installThemeError = function( response ) { wp.updates.installThemeError = function( response ) {
var $card, $button, var $card, $button,
errorMessage = wp.updates.l10n.installFailed.replace( '%s', response.errorMessage ), errorMessage = sprintf(
/* translators: %s: Error string for a failed installation. */
__( 'Installation failed: %s' ),
response.errorMessage
),
$message = wp.updates.adminNotice( { $message = wp.updates.adminNotice( {
className: 'update-message notice-error notice-alt', className: 'update-message notice-error notice-alt',
message: errorMessage message: errorMessage
@ -1217,8 +1356,15 @@
$button $button
.removeClass( 'updating-message' ) .removeClass( 'updating-message' )
.attr( 'aria-label', wp.updates.l10n.themeInstallFailedLabel.replace( '%s', $button.data( 'name' ) ) ) .attr(
.text( wp.updates.l10n.installFailedShort ); 'aria-label',
sprintf(
/* translators: %s: Theme name and version. */
_x( '%s installation failed', 'theme' ),
$button.data( 'name' )
)
)
.text( __( 'Installation Failed!' ) );
wp.a11y.speak( errorMessage, 'assertive' ); wp.a11y.speak( errorMessage, 'assertive' );
@ -1251,13 +1397,13 @@
error: wp.updates.deleteThemeError error: wp.updates.deleteThemeError
}, args ); }, args );
if ( $button && $button.html() !== wp.updates.l10n.deleting ) { if ( $button && $button.html() !== __( 'Deleting...' ) ) {
$button $button
.data( 'originaltext', $button.html() ) .data( 'originaltext', $button.html() )
.text( wp.updates.l10n.deleting ); .text( __( 'Deleting...' ) );
} }
wp.a11y.speak( wp.updates.l10n.deleting, 'polite' ); wp.a11y.speak( __( 'Deleting...' ), 'polite' );
// Remove previous error messages, if any. // Remove previous error messages, if any.
$( '.theme-info .update-message' ).remove(); $( '.theme-info .update-message' ).remove();
@ -1320,7 +1466,7 @@
} ); } );
} }
wp.a11y.speak( wp.updates.l10n.themeDeleted, 'polite' ); wp.a11y.speak( _x( 'Deleted!', 'theme' ), 'polite' );
$document.trigger( 'wp-theme-delete-success', response ); $document.trigger( 'wp-theme-delete-success', response );
}; };
@ -1340,7 +1486,11 @@
$button = $( '.theme-actions .delete-theme' ), $button = $( '.theme-actions .delete-theme' ),
updateRow = wp.template( 'item-update-row' ), updateRow = wp.template( 'item-update-row' ),
$updateRow = $themeRow.siblings( '#' + response.slug + '-update' ), $updateRow = $themeRow.siblings( '#' + response.slug + '-update' ),
errorMessage = wp.updates.l10n.deleteFailed.replace( '%s', response.errorMessage ), errorMessage = sprintf(
/* translators: %s: Error string for a failed deletion. */
__( 'Deletion failed: %s' ),
response.errorMessage
),
$message = wp.updates.adminNotice( { $message = wp.updates.adminNotice( {
className: 'update-message notice-error notice-alt', className: 'update-message notice-error notice-alt',
message: errorMessage message: errorMessage
@ -1631,8 +1781,8 @@
* 'update' or 'install'. * 'update' or 'install'.
*/ */
wp.updates.isValidResponse = function( response, action ) { wp.updates.isValidResponse = function( response, action ) {
var error = wp.updates.l10n.unknownError, var error = __( 'Something went wrong.' ),
errorMessage; errorMessage;
// Make sure the response is a valid data object and not a Promise object. // Make sure the response is a valid data object and not a Promise object.
if ( _.isObject( response ) && ! _.isFunction( response.always ) ) { if ( _.isObject( response ) && ! _.isFunction( response.always ) ) {
@ -1640,11 +1790,11 @@
} }
if ( _.isString( response ) && '-1' === response ) { if ( _.isString( response ) && '-1' === response ) {
error = wp.updates.l10n.nonceError; error = __( 'An error has occurred. Please reload the page and try again.' );
} else if ( _.isString( response ) ) { } else if ( _.isString( response ) ) {
error = response; error = response;
} else if ( 'undefined' !== typeof response.readyState && 0 === response.readyState ) { } else if ( 'undefined' !== typeof response.readyState && 0 === response.readyState ) {
error = wp.updates.l10n.connectionError; error = __( 'Connection lost or the server is busy. Please try again later.' );
} else if ( _.isString( response.responseText ) && '' !== response.responseText ) { } else if ( _.isString( response.responseText ) && '' !== response.responseText ) {
error = response.responseText; error = response.responseText;
} else if ( _.isString( response.statusText ) ) { } else if ( _.isString( response.statusText ) ) {
@ -1653,15 +1803,18 @@
switch ( action ) { switch ( action ) {
case 'update': case 'update':
errorMessage = wp.updates.l10n.updateFailed; /* translators: %s: Error string for a failed update. */
errorMessage = __( 'Update Failed: %s' );
break; break;
case 'install': case 'install':
errorMessage = wp.updates.l10n.installFailed; /* translators: %s: Error string for a failed installation. */
errorMessage = __( 'Installation failed: %s' );
break; break;
case 'delete': case 'delete':
errorMessage = wp.updates.l10n.deleteFailed; /* translators: %s: Error string for a failed deletion. */
errorMessage = __( 'Deletion failed: %s' );
break; break;
} }
@ -1685,7 +1838,7 @@
.removeClass( 'updating-message' ) .removeClass( 'updating-message' )
.removeAttr( 'aria-label' ) .removeAttr( 'aria-label' )
.prop( 'disabled', true ) .prop( 'disabled', true )
.text( wp.updates.l10n.updateFailedShort ); .text( __( 'Update Failed!' ) );
$( '.updating-message:not(.button):not(.thickbox)' ) $( '.updating-message:not(.button):not(.thickbox)' )
.removeClass( 'updating-message notice-warning' ) .removeClass( 'updating-message notice-warning' )
@ -1709,7 +1862,7 @@
*/ */
wp.updates.beforeunload = function() { wp.updates.beforeunload = function() {
if ( wp.updates.ajaxLocked ) { if ( wp.updates.ajaxLocked ) {
return wp.updates.l10n.beforeunload; return __( 'Updates may not complete if you navigate away from this page.' );
} }
}; };
@ -1822,14 +1975,28 @@
if ( 'plugin-install' === pagenow || 'plugin-install-network' === pagenow ) { if ( 'plugin-install' === pagenow || 'plugin-install-network' === pagenow ) {
if ( 'update-plugin' === job.action ) { if ( 'update-plugin' === job.action ) {
$message.attr( 'aria-label', wp.updates.l10n.pluginUpdateNowLabel.replace( '%s', $message.data( 'name' ) ) ); $message.attr(
'aria-label',
sprintf(
/* translators: %s: Plugin name and version. */
_x( 'Update %s now', 'plugin' ),
$message.data( 'name' )
)
);
} else if ( 'install-plugin' === job.action ) { } else if ( 'install-plugin' === job.action ) {
$message.attr( 'aria-label', wp.updates.l10n.pluginInstallNowLabel.replace( '%s', $message.data( 'name' ) ) ); $message.attr(
'aria-label',
sprintf(
/* translators: %s: Plugin name. */
_x( 'Install %s now', 'plugin' ),
$message.data( 'name' )
)
);
} }
} }
} }
wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' ); wp.a11y.speak( __( 'Update canceled.' ), 'polite' );
} ); } );
/** /**
@ -1905,9 +2072,9 @@
$message $message
.removeClass( 'updating-message' ) .removeClass( 'updating-message' )
.text( wp.updates.l10n.installNow ); .text( __( 'Install Now' ) );
wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' ); wp.a11y.speak( __( 'Update canceled.' ), 'polite' );
} ); } );
} }
@ -1940,10 +2107,17 @@
$button $button
.removeClass( 'updating-message' ) .removeClass( 'updating-message' )
.text( wp.updates.l10n.installNow ) .attr(
.attr( 'aria-label', wp.updates.l10n.pluginInstallNowLabel.replace( '%s', pluginName ) ); 'aria-label',
sprintf(
/* translators: %s: Plugin name. */
_x( 'Install %s now', 'plugin' ),
pluginName
)
)
.text( __( 'Install Now' ) );
wp.a11y.speak( wp.updates.l10n.updateCancel, 'polite' ); wp.a11y.speak( __( 'Update canceled.' ), 'polite' );
} ); } );
} }
@ -1963,11 +2137,16 @@
* @param {Event} event Event interface. * @param {Event} event Event interface.
*/ */
$bulkActionForm.on( 'click', '[data-plugin] a.delete', function( event ) { $bulkActionForm.on( 'click', '[data-plugin] a.delete', function( event ) {
var $pluginRow = $( event.target ).parents( 'tr' ); var $pluginRow = $( event.target ).parents( 'tr' ),
confirmMessage = sprintf(
/* translators: %s: Plugin name. */
__( 'Are you sure you want to delete %s and its data?' ),
$pluginRow.find( '.plugin-title strong' ).text()
);
event.preventDefault(); event.preventDefault();
if ( ! window.confirm( wp.updates.l10n.aysDeleteUninstall.replace( '%s', $pluginRow.find( '.plugin-title strong' ).text() ) ) ) { if ( ! window.confirm( confirmMessage ) ) {
return; return;
} }
@ -2014,11 +2193,16 @@
* @param {Event} event Event interface. * @param {Event} event Event interface.
*/ */
$document.on( 'click', '.themes-php.network-admin a.delete', function( event ) { $document.on( 'click', '.themes-php.network-admin a.delete', function( event ) {
var $themeRow = $( event.target ).parents( 'tr' ); var $themeRow = $( event.target ).parents( 'tr' ),
confirmMessage = sprintf(
/* translators: %s: Theme name. */
__( 'Are you sure you want to delete %s?' ),
$themeRow.find( '.theme-title strong' ).text()
);
event.preventDefault(); event.preventDefault();
if ( ! window.confirm( wp.updates.l10n.aysDelete.replace( '%s', $themeRow.find( '.theme-title strong' ).text() ) ) ) { if ( ! window.confirm( confirmMessage ) ) {
return; return;
} }
@ -2069,7 +2253,7 @@
return wp.updates.addAdminNotice( { return wp.updates.addAdminNotice( {
id: 'no-items-selected', id: 'no-items-selected',
className: 'notice-error is-dismissible', className: 'notice-error is-dismissible',
message: wp.updates.l10n.noItemsSelected message: __( 'Please select at least one item to perform this action on.' )
} ); } );
} }
@ -2080,7 +2264,11 @@
break; break;
case 'delete-selected': case 'delete-selected':
if ( ! window.confirm( 'plugin' === type ? wp.updates.l10n.aysBulkDelete : wp.updates.l10n.aysBulkDeleteThemes ) ) { var confirmMessage = 'plugin' === type ?
__( 'Are you sure you want to delete the selected plugins and their data?' ) :
__( 'Caution: These themes may be active on other sites in the network. Are you sure you want to proceed?' );
if ( ! window.confirm( confirmMessage ) ) {
event.preventDefault(); event.preventDefault();
return; return;
} }
@ -2217,7 +2405,7 @@
.append( $( '<a />', { .append( $( '<a />', {
'class': 'current', 'class': 'current',
'href': searchLocation, 'href': searchLocation,
'text': wp.updates.l10n.searchResultsLabel 'text': __( 'Search Results' )
} ) ); } ) );
$( '.wp-filter .filter-links .current' ) $( '.wp-filter .filter-links .current' )
@ -2240,9 +2428,15 @@
delete wp.updates.searchRequest; delete wp.updates.searchRequest;
if ( 0 === response.count ) { if ( 0 === response.count ) {
wp.a11y.speak( wp.updates.l10n.noPluginsFound ); wp.a11y.speak( __( 'You do not appear to have any plugins available at this time.' ) );
} else { } else {
wp.a11y.speak( wp.updates.l10n.pluginsFound.replace( '%d', response.count ) ); wp.a11y.speak(
sprintf(
/* translators: %s: Number of plugins. */
__( 'Number of plugins found: %d' ),
response.count
)
);
} }
} ); } );
}, 1000 ) ); }, 1000 ) );
@ -2298,7 +2492,12 @@
wp.updates.searchRequest = wp.ajax.post( 'search-plugins', data ).done( function( response ) { wp.updates.searchRequest = wp.ajax.post( 'search-plugins', data ).done( function( response ) {
// Can we just ditch this whole subtitle business? // Can we just ditch this whole subtitle business?
var $subTitle = $( '<span />' ).addClass( 'subtitle' ).html( wp.updates.l10n.searchResults.replace( '%s', _.escape( data.s ) ) ), var $subTitle = $( '<span />' ).addClass( 'subtitle' ).html(
sprintf(
/* translators: %s: Search query. */
__( 'Search results for &#8220;%s&#8221;' ),
_.escape( data.s )
) ),
$oldSubTitle = $( '.wrap .subtitle' ); $oldSubTitle = $( '.wrap .subtitle' );
if ( ! data.s.length ) { if ( ! data.s.length ) {
@ -2315,9 +2514,15 @@
delete wp.updates.searchRequest; delete wp.updates.searchRequest;
if ( 0 === response.count ) { if ( 0 === response.count ) {
wp.a11y.speak( wp.updates.l10n.noPluginsFound ); wp.a11y.speak( __( 'No plugins found. Try a different search.' ) );
} else { } else {
wp.a11y.speak( wp.updates.l10n.pluginsFound.replace( '%d', response.count ) ); wp.a11y.speak(
sprintf(
/* translators: %s: Number of plugins. */
__( 'Number of plugins found: %d' ),
response.count
)
);
} }
} ); } );
}, 500 ) ); }, 500 ) );
@ -2518,9 +2723,9 @@
// Show loading status. // Show loading status.
if ( 'enable' === action ) { if ( 'enable' === action ) {
$label.text( wp.updates.l10n.autoUpdatesEnabling ); $label.text( __( 'Enabling...' ) );
} else { } else {
$label.text( wp.updates.l10n.autoUpdatesDisabling ); $label.text( __( 'Disabling...' ) );
} }
$anchor.find( '.dashicons-update' ).removeClass( 'hidden' ); $anchor.find( '.dashicons-update' ).removeClass( 'hidden' );
@ -2544,7 +2749,7 @@
if ( response.data && response.data.error ) { if ( response.data && response.data.error ) {
errorMessage = response.data.error; errorMessage = response.data.error;
} else { } else {
errorMessage = wp.updates.l10n.autoUpdatesError; errorMessage = __( 'The request could not be completed.' );
} }
$parent.find( '.notice.error' ).removeClass( 'hidden' ).find( 'p' ).text( errorMessage ); $parent.find( '.notice.error' ).removeClass( 'hidden' ).find( 'p' ).text( errorMessage );
@ -2585,9 +2790,9 @@
href: href href: href
} ); } );
$label.text( wp.updates.l10n.autoUpdatesDisable ); $label.text( __( 'Disable auto-updates' ) );
$parent.find( '.auto-update-time' ).removeClass( 'hidden' ); $parent.find( '.auto-update-time' ).removeClass( 'hidden' );
wp.a11y.speak( wp.updates.l10n.autoUpdatesEnabled, 'polite' ); wp.a11y.speak( __( 'Enable auto-updates' ), 'polite' );
} else { } else {
href = href.replace( 'action=disable-auto-update', 'action=enable-auto-update' ); href = href.replace( 'action=disable-auto-update', 'action=enable-auto-update' );
$anchor.attr( { $anchor.attr( {
@ -2595,16 +2800,20 @@
href: href href: href
} ); } );
$label.text( wp.updates.l10n.autoUpdatesEnable ); $label.text( __( 'Enable auto-updates' ) );
$parent.find( '.auto-update-time' ).addClass( 'hidden' ); $parent.find( '.auto-update-time' ).addClass( 'hidden' );
wp.a11y.speak( wp.updates.l10n.autoUpdatesDisabled, 'polite' ); wp.a11y.speak( __( 'Auto-updates disabled' ), 'polite' );
} }
$document.trigger( 'wp-auto-update-setting-changed', { state: action, type: type, asset: asset } ); $document.trigger( 'wp-auto-update-setting-changed', { state: action, type: type, asset: asset } );
} ) } )
.fail( function() { .fail( function() {
$parent.find( '.notice.error' ).removeClass( 'hidden' ).find( 'p' ).text( wp.updates.l10n.autoUpdatesError ); $parent.find( '.notice.error' )
wp.a11y.speak( wp.updates.l10n.autoUpdatesError, 'polite' ); .removeClass( 'hidden' )
.find( 'p' )
.text( __( 'The request could not be completed.' ) );
wp.a11y.speak( __( 'The request could not be completed.' ), 'polite' );
} ) } )
.always( function() { .always( function() {
$anchor.removeAttr( 'data-doing-ajax' ).find( '.dashicons-update' ).addClass( 'hidden' ); $anchor.removeAttr( 'data-doing-ajax' ).find( '.dashicons-update' ).addClass( 'hidden' );

File diff suppressed because one or more lines are too long

View File

@ -1434,100 +1434,12 @@ function wp_default_scripts( $scripts ) {
); );
$scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize' ), false, 1 ); $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize' ), false, 1 );
$scripts->set_translations( 'updates' );
did_action( 'init' ) && $scripts->localize( did_action( 'init' ) && $scripts->localize(
'updates', 'updates',
'_wpUpdatesSettings', '_wpUpdatesSettings',
array( array(
'ajax_nonce' => wp_create_nonce( 'updates' ), 'ajax_nonce' => wp_create_nonce( 'updates' ),
'l10n' => array(
/* translators: %s: Search query. */
'searchResults' => __( 'Search results for &#8220;%s&#8221;' ),
'searchResultsLabel' => __( 'Search Results' ),
'noPlugins' => __( 'You do not appear to have any plugins available at this time.' ),
'noItemsSelected' => __( 'Please select at least one item to perform this action on.' ),
'updating' => __( 'Updating...' ), // No ellipsis.
'pluginUpdated' => _x( 'Updated!', 'plugin' ),
'themeUpdated' => _x( 'Updated!', 'theme' ),
'update' => __( 'Update' ),
'updateNow' => __( 'Update Now' ),
/* translators: %s: Plugin name and version. */
'pluginUpdateNowLabel' => _x( 'Update %s now', 'plugin' ),
'updateFailedShort' => __( 'Update Failed!' ),
/* translators: %s: Error string for a failed update. */
'updateFailed' => __( 'Update Failed: %s' ),
/* translators: %s: Plugin name and version. */
'pluginUpdatingLabel' => _x( 'Updating %s...', 'plugin' ), // No ellipsis.
/* translators: %s: Plugin name and version. */
'pluginUpdatedLabel' => _x( '%s updated!', 'plugin' ),
/* translators: %s: Plugin name and version. */
'pluginUpdateFailedLabel' => _x( '%s update failed', 'plugin' ),
/* translators: Accessibility text. */
'updatingMsg' => __( 'Updating... please wait.' ), // No ellipsis.
/* translators: Accessibility text. */
'updatedMsg' => __( 'Update completed successfully.' ),
/* translators: Accessibility text. */
'updateCancel' => __( 'Update canceled.' ),
'beforeunload' => __( 'Updates may not complete if you navigate away from this page.' ),
'installNow' => __( 'Install Now' ),
/* translators: %s: Plugin name. */
'pluginInstallNowLabel' => _x( 'Install %s now', 'plugin' ),
'installing' => __( 'Installing...' ),
'pluginInstalled' => _x( 'Installed!', 'plugin' ),
'themeInstalled' => _x( 'Installed!', 'theme' ),
'installFailedShort' => __( 'Installation Failed!' ),
/* translators: %s: Error string for a failed installation. */
'installFailed' => __( 'Installation failed: %s' ),
/* translators: %s: Plugin name and version. */
'pluginInstallingLabel' => _x( 'Installing %s...', 'plugin' ), // No ellipsis.
/* translators: %s: Theme name and version. */
'themeInstallingLabel' => _x( 'Installing %s...', 'theme' ), // No ellipsis.
/* translators: %s: Plugin name and version. */
'pluginInstalledLabel' => _x( '%s installed!', 'plugin' ),
/* translators: %s: Theme name and version. */
'themeInstalledLabel' => _x( '%s installed!', 'theme' ),
/* translators: %s: Plugin name and version. */
'pluginInstallFailedLabel' => _x( '%s installation failed', 'plugin' ),
/* translators: %s: Theme name and version. */
'themeInstallFailedLabel' => _x( '%s installation failed', 'theme' ),
'installingMsg' => __( 'Installing... please wait.' ),
'installedMsg' => __( 'Installation completed successfully.' ),
/* translators: %s: Activation URL. */
'importerInstalledMsg' => __( 'Importer installed successfully. <a href="%s">Run importer</a>' ),
/* translators: %s: Theme name. */
'aysDelete' => __( 'Are you sure you want to delete %s?' ),
/* translators: %s: Plugin name. */
'aysDeleteUninstall' => __( 'Are you sure you want to delete %s and its data?' ),
'aysBulkDelete' => __( 'Are you sure you want to delete the selected plugins and their data?' ),
'aysBulkDeleteThemes' => __( 'Caution: These themes may be active on other sites in the network. Are you sure you want to proceed?' ),
'deleting' => __( 'Deleting...' ),
/* translators: %s: Error string for a failed deletion. */
'deleteFailed' => __( 'Deletion failed: %s' ),
'pluginDeleted' => _x( 'Deleted!', 'plugin' ),
'themeDeleted' => _x( 'Deleted!', 'theme' ),
'livePreview' => __( 'Live Preview' ),
'activatePlugin' => is_network_admin() ? __( 'Network Activate' ) : __( 'Activate' ),
'activateTheme' => is_network_admin() ? __( 'Network Enable' ) : __( 'Activate' ),
/* translators: %s: Plugin name. */
'activatePluginLabel' => is_network_admin() ? _x( 'Network Activate %s', 'plugin' ) : _x( 'Activate %s', 'plugin' ),
/* translators: %s: Theme name. */
'activateThemeLabel' => is_network_admin() ? _x( 'Network Activate %s', 'theme' ) : _x( 'Activate %s', 'theme' ),
'activateImporter' => __( 'Run Importer' ),
/* translators: %s: Importer name. */
'activateImporterLabel' => __( 'Run %s' ),
'unknownError' => __( 'Something went wrong.' ),
'connectionError' => __( 'Connection lost or the server is busy. Please try again later.' ),
'nonceError' => __( 'An error has occurred. Please reload the page and try again.' ),
/* translators: %s: Number of plugins. */
'pluginsFound' => __( 'Number of plugins found: %d' ),
'noPluginsFound' => __( 'No plugins found. Try a different search.' ),
'autoUpdatesEnable' => __( 'Enable auto-updates' ),
'autoUpdatesEnabling' => __( 'Enabling...' ),
'autoUpdatesEnabled' => __( 'Auto-updates enabled' ),
'autoUpdatesDisable' => __( 'Disable auto-updates' ),
'autoUpdatesDisabling' => __( 'Disabling...' ),
'autoUpdatesDisabled' => __( 'Auto-updates disabled' ),
'autoUpdatesError' => __( 'The request could not be completed.' ),
),
) )
); );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-alpha-47883'; $wp_version = '5.5-alpha-47884';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.