WordPress.org

Make WordPress Core

Changeset 48350


Ignore:
Timestamp:
07/06/2020 08:58:06 PM (3 months ago)
Author:
ocean90
Message:

I18N: Use wp.i18n for translatable strings in wp-admin/js/tags-box.js and wp-admin/js/tags-suggest.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 #50579.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/tags-box.js

    r48168 r48350  
    77
    88( function( $ ) {
    9     var tagDelimiter = ( window.tagsSuggestL10n && window.tagsSuggestL10n.tagDelimiter ) || ',';
     9    var tagDelimiter = wp.i18n._x( ',', 'tag delimiter' ) || ',';
    1010
    1111    /**
     
    165165                    xbutton = $( '<button type="button" id="' + id + '-check-num-' + key + '" class="ntdelbutton">' +
    166166                        '<span class="remove-tag-icon" aria-hidden="true"></span>' +
    167                         '<span class="screen-reader-text">' + window.tagsSuggestL10n.removeTerm + ' ' + listItem.html() + '</span>' +
     167                        '<span class="screen-reader-text">' + wp.i18n.__( 'Remove term:' ) + ' ' + listItem.html() + '</span>' +
    168168                        '</button>' );
    169169
     
    335335            switch ( this.userAction ) {
    336336                case 'remove':
    337                     message = window.tagsSuggestL10n.termRemoved;
     337                    message = wp.i18n.__( 'Term removed.' );
    338338                    break;
    339339
    340340                case 'add':
    341                     message = window.tagsSuggestL10n.termAdded;
     341                    message = wp.i18n.__( 'Term added.' );
    342342                    break;
    343343
  • trunk/src/js/_enqueues/admin/tags-suggest.js

    r47122 r48350  
    55 */
    66( function( $ ) {
    7     if ( typeof window.tagsSuggestL10n === 'undefined' || typeof window.uiAutocompleteL10n === 'undefined' ) {
     7    if ( typeof window.uiAutocompleteL10n === 'undefined' ) {
    88        return;
    99    }
    1010
    1111    var tempID = 0;
    12     var separator = window.tagsSuggestL10n.tagDelimiter || ',';
     12    var separator = wp.i18n._x( ',', 'tag delimiter' ) || ',';
    1313
    1414    function split( val ) {
     
    105105                if ( $.ui.keyCode.TAB === event.keyCode ) {
    106106                    // Audible confirmation message when a tag has been selected.
    107                     window.wp.a11y.speak( window.tagsSuggestL10n.termSelected, 'assertive' );
     107                    window.wp.a11y.speak( wp.i18n.__( 'Term selected.' ), 'assertive' );
    108108                    event.preventDefault();
    109109                } else if ( $.ui.keyCode.ENTER === event.keyCode ) {
  • trunk/src/wp-includes/script-loader.php

    r48348 r48350  
    12131213
    12141214        $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'tags-suggest' ), false, 1 );
     1215        $scripts->set_translations( 'tags-box' );
    12151216
    12161217        $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 );
    1217         did_action( 'init' ) && $scripts->localize(
    1218             'tags-suggest',
    1219             'tagsSuggestL10n',
    1220             array(
    1221                 'tagDelimiter' => _x( ',', 'tag delimiter' ),
    1222                 'removeTerm'   => __( 'Remove term:' ),
    1223                 'termSelected' => __( 'Term selected.' ),
    1224                 'termAdded'    => __( 'Term added.' ),
    1225                 'termRemoved'  => __( 'Term removed.' ),
    1226             )
    1227         );
     1218        $scripts->set_translations( 'tags-suggest' );
    12281219
    12291220        $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y', 'wp-sanitize', 'clipboard' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.