From e39812fe53952569ae19ba031fb8ae839cf4262c Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 7 Jul 2020 16:07:25 +0000 Subject: [PATCH] I18N: Use `wp.i18n` for translatable strings in `wp-admin/js/color-picker.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 #50596. git-svn-id: https://develop.svn.wordpress.org/trunk@48383 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/lib/color-picker.js | 16 ++++++++-------- src/wp-includes/script-loader.php | 13 +------------ 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/js/_enqueues/lib/color-picker.js b/src/js/_enqueues/lib/color-picker.js index 18f2bc26dc..83e7dc663e 100644 --- a/src/js/_enqueues/lib/color-picker.js +++ b/src/js/_enqueues/lib/color-picker.js @@ -2,7 +2,6 @@ * @output wp-admin/js/color-picker.js */ -/* global wpColorPickerL10n */ ( function( $, undef ) { var ColorPicker, @@ -11,7 +10,8 @@ _wrap = '
', _button = '', _wrappingLabel = '', - _wrappingLabelText = ''; + _wrappingLabelText = '', + __ = wp.i18n.__; /** * Creates a jQuery UI color picker that is used in the theme customizer. @@ -118,7 +118,7 @@ // Insert the default label text. self.wrappingLabelText = $( _wrappingLabelText ) .insertBefore( el ) - .text( wpColorPickerL10n.defaultLabel ); + .text( __( 'Color value' ) ); } /* @@ -136,7 +136,7 @@ .insertBefore( self.wrappingLabel ) .css( { backgroundColor: self.initialValue } ); // Set the toggle button span element text. - self.toggler.find( '.wp-color-result-text' ).text( wpColorPickerL10n.pick ); + self.toggler.find( '.wp-color-result-text' ).text( __( 'Select Color' ) ); // Set up the Iris container and insert it after the wrapping label. self.pickerContainer = $( _after ).insertAfter( self.wrappingLabel ); // Store a reference to the Clear/Default button. @@ -146,13 +146,13 @@ if ( self.options.defaultColor ) { self.button .addClass( 'wp-picker-default' ) - .val( wpColorPickerL10n.defaultString ) - .attr( 'aria-label', wpColorPickerL10n.defaultAriaLabel ); + .val( __( 'Default' ) ) + .attr( 'aria-label', __( 'Select default color' ) ); } else { self.button .addClass( 'wp-picker-clear' ) - .val( wpColorPickerL10n.clear ) - .attr( 'aria-label', wpColorPickerL10n.clearAriaLabel ); + .val( __( 'Clear' ) ) + .attr( 'aria-label', __( 'Clear color' ) ); } // Wrap the wrapping label in its wrapper and append the Clear/Default button. diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index a7a19aa8e7..bc762340ca 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -1349,18 +1349,7 @@ function wp_default_scripts( $scripts ) { $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), '1.0.7', 1 ); $scripts->add( 'wp-color-picker', "/wp-admin/js/color-picker$suffix.js", array( 'iris' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( - 'wp-color-picker', - 'wpColorPickerL10n', - array( - 'clear' => __( 'Clear' ), - 'clearAriaLabel' => __( 'Clear color' ), - 'defaultString' => __( 'Default' ), - 'defaultAriaLabel' => __( 'Select default color' ), - 'pick' => __( 'Select Color' ), - 'defaultLabel' => __( 'Color value' ), - ) - ); + $scripts->set_translations( 'wp-color-picker' ); $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-util', 'wp-a11y' ), false, 1 );