From 06f788f62212adc7e997d6f3e085014dde47a893 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Wed, 1 Jul 2020 19:48:30 +0000 Subject: [PATCH] I18N: Use `wp.i18n` for translatable strings in `wp-admin/js/common.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 #50526. git-svn-id: https://develop.svn.wordpress.org/trunk@48267 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/admin/common.js | 21 +++++++++++---------- src/wp-includes/script-loader.php | 15 +++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/js/_enqueues/admin/common.js b/src/js/_enqueues/admin/common.js index 4b287f6cd5..8734ee72f4 100644 --- a/src/js/_enqueues/admin/common.js +++ b/src/js/_enqueues/admin/common.js @@ -2,7 +2,7 @@ * @output wp-admin/js/common.js */ -/* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */ +/* global setUserSetting, ajaxurl, alert, confirm, pagenow */ /* global columns, screenMeta */ /** @@ -15,7 +15,8 @@ ( function( $, window, undefined ) { var $document = $( document ), $window = $( window ), - $body = $( document.body ); + $body = $( document.body ), + __ = wp.i18n.__; /** * Removed in 3.3.0, needed for back-compatibility. @@ -188,8 +189,7 @@ window.showNotice = { * @return {boolean} Returns true if the message is confirmed. */ warn : function() { - var msg = commonL10n.warnDelete || ''; - if ( confirm(msg) ) { + if ( confirm( __( 'You are about to permanently delete these items from your site.\nThis action cannot be undone.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) { return true; } @@ -757,11 +757,10 @@ $document.ready( function() { function makeNoticesDismissible() { $( '.notice.is-dismissible' ).each( function() { var $el = $( this ), - $button = $( '' ), - btnText = commonL10n.dismiss || ''; + $button = $( '' ); // Ensure plain text. - $button.find( '.screen-reader-text' ).text( btnText ); + $button.find( '.screen-reader-text' ).text( __( 'Dismiss this notice.' ) ); $button.on( 'click.wp-dismiss-notice', function( event ) { event.preventDefault(); $el.fadeTo( 100, 0, function() { @@ -1559,12 +1558,14 @@ $document.ready( function() { */ $document.on( 'wp-menu-state-set wp-collapse-menu', function( event, eventData ) { var $collapseButton = $( '#collapse-button' ), - ariaExpanded = 'true', - ariaLabelText = commonL10n.collapseMenu; + ariaExpanded, ariaLabelText; if ( 'folded' === eventData.state ) { ariaExpanded = 'false'; - ariaLabelText = commonL10n.expandMenu; + ariaLabelText = __( 'Expand Main menu' ); + } else { + ariaExpanded = 'true'; + ariaLabelText = __( 'Collapse Main menu' ); } $collapseButton.attr({ diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 35b5823104..3141b9b897 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -608,16 +608,7 @@ function wp_default_scripts( $scripts ) { ); $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( - 'common', - 'commonL10n', - array( - 'warnDelete' => __( "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ), - 'dismiss' => __( 'Dismiss this notice.' ), - 'collapseMenu' => __( 'Collapse Main menu' ), - 'expandMenu' => __( 'Expand Main menu' ), - ) - ); + $scripts->set_translations( 'common' ); $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 ); @@ -809,8 +800,8 @@ function wp_default_scripts( $scripts ) { // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv. // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way. - $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '4.1.4', 1 ); - $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '4.2.2', 1 ); + $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '3.2.0', 1 ); + $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '3.3.2', 1 ); $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry$dev_suffix.js", array( 'jquery', 'masonry' ), '3.1.2b', 1 ); $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array( 'jquery' ), '3.1-20121105', 1 );