Make WordPress Core

Changeset 48383


Ignore:
Timestamp:
07/07/2020 04:07:25 PM (6 years ago)
Author:
ocean90
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/color-picker.js

    r47122 r48383  
    33 */
    44
    5 /* global wpColorPickerL10n */
    65( function( $, undef ) {
    76
    … …  
    1211                _button = '<input type="button" class="button button-small" />',
    1312                _wrappingLabel = '<label></label>',
    14                 _wrappingLabelText = '<span class="screen-reader-text"></span>';
     13                _wrappingLabelText = '<span class="screen-reader-text"></span>',
     14                __ = wp.i18n.__;
    1515
    1616        /**
    … …  
    119119                                self.wrappingLabelText = $( _wrappingLabelText )
    120120                                        .insertBefore( el )
    121                                         .text( wpColorPickerL10n.defaultLabel );
     121                                        .text( __( 'Color value' ) );
    122122                        }
    123123
    … …  
    137137                                .css( { backgroundColor: self.initialValue } );
    138138                        // Set the toggle button span element text.
    139                         self.toggler.find( '.wp-color-result-text' ).text( wpColorPickerL10n.pick );
     139                        self.toggler.find( '.wp-color-result-text' ).text( __( 'Select Color' ) );
    140140                        // Set up the Iris container and insert it after the wrapping label.
    141141                        self.pickerContainer = $( _after ).insertAfter( self.wrappingLabel );
    … …  
    147147                                self.button
    148148                                        .addClass( 'wp-picker-default' )
    149                                         .val( wpColorPickerL10n.defaultString )
    150                                         .attr( 'aria-label', wpColorPickerL10n.defaultAriaLabel );
     149                                        .val( __( 'Default' ) )
     150                                        .attr( 'aria-label', __( 'Select default color' ) );
    151151                        } else {
    152152                                self.button
    153153                                        .addClass( 'wp-picker-clear' )
    154                                         .val( wpColorPickerL10n.clear )
    155                                         .attr( 'aria-label', wpColorPickerL10n.clearAriaLabel );
     154                                        .val( __( 'Clear' ) )
     155                                        .attr( 'aria-label', __( 'Clear color' ) );
    156156                        }
    157157
  • trunk/src/wp-includes/script-loader.php

    r48375 r48383  
    13501350                $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), '1.0.7', 1 );
    13511351                $scripts->add( 'wp-color-picker', "/wp-admin/js/color-picker$suffix.js", array( 'iris' ), false, 1 );
    1352                 did_action( 'init' ) && $scripts->localize(
    1353                         'wp-color-picker',
    1354                         'wpColorPickerL10n',
    1355                         array(
    1356                                 'clear'            => __( 'Clear' ),
    1357                                 'clearAriaLabel'   => __( 'Clear color' ),
    1358                                 'defaultString'    => __( 'Default' ),
    1359                                 'defaultAriaLabel' => __( 'Select default color' ),
    1360                                 'pick'             => __( 'Select Color' ),
    1361                                 'defaultLabel'     => __( 'Color value' ),
    1362                         )
    1363                 );
     1352                $scripts->set_translations( 'wp-color-picker' );
    13641353
    13651354                $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-util', 'wp-a11y' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.