Skip to content

Commit

Permalink
I18N: Use wp.i18n for translatable strings in `wp-admin/js/color-pi…
Browse files Browse the repository at this point in the history
…cker.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.
Built from https://develop.svn.wordpress.org/trunk@48383


git-svn-id: http://core.svn.wordpress.org/trunk@48152 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
ocean90 committed Jul 7, 2020
1 parent ef78b5b commit 7e7b70c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
16 changes: 8 additions & 8 deletions wp-admin/js/color-picker.js
Expand Up @@ -2,7 +2,6 @@
* @output wp-admin/js/color-picker.js
*/

/* global wpColorPickerL10n */
( function( $, undef ) {

var ColorPicker,
Expand All @@ -11,7 +10,8 @@
_wrap = '<div class="wp-picker-container" />',
_button = '<input type="button" class="button button-small" />',
_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.
Expand Down Expand Up @@ -118,7 +118,7 @@
// Insert the default label text.
self.wrappingLabelText = $( _wrappingLabelText )
.insertBefore( el )
.text( wpColorPickerL10n.defaultLabel );
.text( __( 'Color value' ) );
}

/*
Expand All @@ -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.
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion wp-admin/js/color-picker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions wp-includes/script-loader.php
Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Expand Up @@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.5-alpha-48382';
$wp_version = '5.5-alpha-48383';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 7e7b70c

Please sign in to comment.