From 8c42273b7a248fb662d522e7928f9d3713abdbe0 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 7 Jul 2020 16:59:22 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@48387 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/admin/widgets.js | 24 +++++------------------- src/wp-includes/script-loader.php | 15 +-------------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/src/js/_enqueues/admin/widgets.js b/src/js/_enqueues/admin/widgets.js index a0cb25efb6..b53a7bdcf0 100644 --- a/src/js/_enqueues/admin/widgets.js +++ b/src/js/_enqueues/admin/widgets.js @@ -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 ); }, diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index e6608e0778..edc0afef7f 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -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' );