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
This commit is contained in:
Dominik Schilling 2020-07-07 16:07:25 +00:00
parent e16565b2d4
commit e39812fe53
2 changed files with 9 additions and 20 deletions

View File

@ -2,7 +2,6 @@
* @output wp-admin/js/color-picker.js * @output wp-admin/js/color-picker.js
*/ */
/* global wpColorPickerL10n */
( function( $, undef ) { ( function( $, undef ) {
var ColorPicker, var ColorPicker,
@ -11,7 +10,8 @@
_wrap = '<div class="wp-picker-container" />', _wrap = '<div class="wp-picker-container" />',
_button = '<input type="button" class="button button-small" />', _button = '<input type="button" class="button button-small" />',
_wrappingLabel = '<label></label>', _wrappingLabel = '<label></label>',
_wrappingLabelText = '<span class="screen-reader-text"></span>'; _wrappingLabelText = '<span class="screen-reader-text"></span>',
__ = wp.i18n.__;
/** /**
* Creates a jQuery UI color picker that is used in the theme customizer. * Creates a jQuery UI color picker that is used in the theme customizer.
@ -118,7 +118,7 @@
// Insert the default label text. // Insert the default label text.
self.wrappingLabelText = $( _wrappingLabelText ) self.wrappingLabelText = $( _wrappingLabelText )
.insertBefore( el ) .insertBefore( el )
.text( wpColorPickerL10n.defaultLabel ); .text( __( 'Color value' ) );
} }
/* /*
@ -136,7 +136,7 @@
.insertBefore( self.wrappingLabel ) .insertBefore( self.wrappingLabel )
.css( { backgroundColor: self.initialValue } ); .css( { backgroundColor: self.initialValue } );
// Set the toggle button span element text. // 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. // Set up the Iris container and insert it after the wrapping label.
self.pickerContainer = $( _after ).insertAfter( self.wrappingLabel ); self.pickerContainer = $( _after ).insertAfter( self.wrappingLabel );
// Store a reference to the Clear/Default button. // Store a reference to the Clear/Default button.
@ -146,13 +146,13 @@
if ( self.options.defaultColor ) { if ( self.options.defaultColor ) {
self.button self.button
.addClass( 'wp-picker-default' ) .addClass( 'wp-picker-default' )
.val( wpColorPickerL10n.defaultString ) .val( __( 'Default' ) )
.attr( 'aria-label', wpColorPickerL10n.defaultAriaLabel ); .attr( 'aria-label', __( 'Select default color' ) );
} else { } else {
self.button self.button
.addClass( 'wp-picker-clear' ) .addClass( 'wp-picker-clear' )
.val( wpColorPickerL10n.clear ) .val( __( 'Clear' ) )
.attr( 'aria-label', wpColorPickerL10n.clearAriaLabel ); .attr( 'aria-label', __( 'Clear color' ) );
} }
// Wrap the wrapping label in its wrapper and append the Clear/Default button. // Wrap the wrapping label in its wrapper and append the Clear/Default button.

View File

@ -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( '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 ); $scripts->add( 'wp-color-picker', "/wp-admin/js/color-picker$suffix.js", array( 'iris' ), false, 1 );
did_action( 'init' ) && $scripts->localize( $scripts->set_translations( 'wp-color-picker' );
'wp-color-picker',
'wpColorPickerL10n',
array(
'clear' => __( 'Clear' ),
'clearAriaLabel' => __( 'Clear color' ),
'defaultString' => __( 'Default' ),
'defaultAriaLabel' => __( 'Select default color' ),
'pick' => __( 'Select Color' ),
'defaultLabel' => __( 'Color value' ),
)
);
$scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-util', 'wp-a11y' ), false, 1 ); $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-util', 'wp-a11y' ), false, 1 );