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

This removes the usage of `$scripts->add_inline_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.

Fixes #50600.
Built from https://develop.svn.wordpress.org/trunk@48387


git-svn-id: http://core.svn.wordpress.org/trunk@48156 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2020-07-07 17:01:06 +00:00
parent d1dc207128
commit 4a21cda313
4 changed files with 8 additions and 35 deletions

View File

@ -15,20 +15,6 @@ window.wpWidgets = {
*/
hoveredSidebar: null,
/**
* Translations.
*
* Exported from PHP in wp_default_scripts().
*
* @var {object}
*/
l10n: {
save: '{save}',
saved: '{saved}',
saveAlert: '{saveAlert}',
widgetAdded: '{widgetAdded}'
},
/**
* Lookup of which widgets have had change events triggered.
*
@ -109,7 +95,7 @@ window.wpWidgets = {
$( this ).find( '.widget-inside :tabbable:first' ).focus();
} );
event.returnValue = wpWidgets.l10n.saveAlert;
event.returnValue = wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
return event.returnValue;
}
});
@ -141,11 +127,11 @@ window.wpWidgets = {
// Save button is initially disabled, but is enabled when a field is changed.
if ( ! widget.data( 'dirty-state-initialized' ) ) {
saveButton = inside.find( '.widget-control-save' );
saveButton.prop( 'disabled', true ).val( wpWidgets.l10n.saved );
saveButton.prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
inside.on( 'input change', function() {
self.dirtyWidgets[ widgetId ] = true;
widget.addClass( 'widget-dirty' );
saveButton.prop( 'disabled', false ).val( wpWidgets.l10n.save );
saveButton.prop( 'disabled', false ).val( wp.i18n.__( 'Save' ) );
});
widget.data( 'dirty-state-initialized', true );
}
@ -586,7 +572,7 @@ window.wpWidgets = {
wpWidgets.appendTitle( widget );
// Re-disable the save button.
widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wpWidgets.l10n.saved );
widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
widget.removeClass( 'widget-dirty' );
@ -717,7 +703,7 @@ window.wpWidgets = {
// have to queue this "by hand".
widget.find( '.widget-title' ).trigger('click');
// At the end of the animation, announce the widget has been added.
window.wp.a11y.speak( wpWidgets.l10n.widgetAdded, 'assertive' );
window.wp.a11y.speak( wp.i18n.__( 'Widget has been added to the selected sidebar' ), 'assertive' );
}, 250 );
},

File diff suppressed because one or more lines are too long

View File

@ -1239,20 +1239,7 @@ function wp_default_scripts( $scripts ) {
$scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ) );
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-a11y' ), false, 1 );
did_action( 'init' ) && $scripts->add_inline_script(
'admin-widgets',
sprintf(
'wpWidgets.l10n = %s;',
wp_json_encode(
array(
'save' => __( 'Save' ),
'saved' => __( 'Saved' ),
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
'widgetAdded' => __( 'Widget has been added to the selected sidebar' ),
)
)
)
);
$scripts->set_translations( 'admin-widgets' );
$scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) );
$scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' );

View File

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