Make WordPress Core

Changeset 48387


Ignore:
Timestamp:
07/07/2020 04:59:22 PM (4 years ago)
Author:
ocean90
Message:

I18N: Use wp.i18n for translatable strings in wp-admin/js/widgets.js.

This removes the usage of $scripts->add_inline_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.

Fixes #50600.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/widgets.js

    r47263 r48387  
    1515     */
    1616    hoveredSidebar: null,
    17 
    18     /**
    19      * Translations.
    20      *
    21      * Exported from PHP in wp_default_scripts().
    22      *
    23      * @var {object}
    24      */
    25     l10n: {
    26         save: '{save}',
    27         saved: '{saved}',
    28         saveAlert: '{saveAlert}',
    29         widgetAdded: '{widgetAdded}'
    30     },
    3117
    3218    /**
     
    11096                } );
    11197
    112                 event.returnValue = wpWidgets.l10n.saveAlert;
     98                event.returnValue = wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
    11399                return event.returnValue;
    114100            }
     
    142128                if ( ! widget.data( 'dirty-state-initialized' ) ) {
    143129                    saveButton = inside.find( '.widget-control-save' );
    144                     saveButton.prop( 'disabled', true ).val( wpWidgets.l10n.saved );
     130                    saveButton.prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
    145131                    inside.on( 'input change', function() {
    146132                        self.dirtyWidgets[ widgetId ] = true;
    147133                        widget.addClass( 'widget-dirty' );
    148                         saveButton.prop( 'disabled', false ).val( wpWidgets.l10n.save );
     134                        saveButton.prop( 'disabled', false ).val( wp.i18n.__( 'Save' ) );
    149135                    });
    150136                    widget.data( 'dirty-state-initialized', true );
     
    587573
    588574                    // Re-disable the save button.
    589                     widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wpWidgets.l10n.saved );
     575                    widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
    590576
    591577                    widget.removeClass( 'widget-dirty' );
     
    718704            widget.find( '.widget-title' ).trigger('click');
    719705            // At the end of the animation, announce the widget has been added.
    720             window.wp.a11y.speak( wpWidgets.l10n.widgetAdded, 'assertive' );
     706            window.wp.a11y.speak( wp.i18n.__( 'Widget has been added to the selected sidebar' ), 'assertive' );
    721707        }, 250 );
    722708    },
  • trunk/src/wp-includes/script-loader.php

    r48385 r48387  
    12401240
    12411241        $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-a11y' ), false, 1 );
    1242         did_action( 'init' ) && $scripts->add_inline_script(
    1243             'admin-widgets',
    1244             sprintf(
    1245                 'wpWidgets.l10n = %s;',
    1246                 wp_json_encode(
    1247                     array(
    1248                         'save'        => __( 'Save' ),
    1249                         'saved'       => __( 'Saved' ),
    1250                         'saveAlert'   => __( 'The changes you made will be lost if you navigate away from this page.' ),
    1251                         'widgetAdded' => __( 'Widget has been added to the selected sidebar' ),
    1252                     )
    1253                 )
    1254             )
    1255         );
     1242        $scripts->set_translations( 'admin-widgets' );
    12561243
    12571244        $scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) );
Note: See TracChangeset for help on using the changeset viewer.