Make WordPress Core

Changeset 48267


Ignore:
Timestamp:
07/01/2020 07:48:30 PM (5 years ago)
Author:
ocean90
Message:

I18N: Use wp.i18n for translatable strings in wp-admin/js/common.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 #50526.

Location:
trunk/src
Files:
2 edited

Legend:

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

    r47771 r48267  
    33 */
    44
    5 /* global setUserSetting, ajaxurl, commonL10n, alert, confirm, pagenow */
     5/* global setUserSetting, ajaxurl, alert, confirm, pagenow */
    66/* global columns, screenMeta */
    77
     
    1616    var $document = $( document ),
    1717        $window = $( window ),
    18         $body = $( document.body );
     18        $body = $( document.body ),
     19        __ = wp.i18n.__;
    1920
    2021/**
     
    189190     */
    190191    warn : function() {
    191         var msg = commonL10n.warnDelete || '';
    192         if ( confirm(msg) ) {
     192        if ( confirm( __( 'You are about to permanently delete these items from your site.\nThis action cannot be undone.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) {
    193193            return true;
    194194        }
     
    758758        $( '.notice.is-dismissible' ).each( function() {
    759759            var $el = $( this ),
    760                 $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' ),
    761                 btnText = commonL10n.dismiss || '';
     760                $button = $( '<button type="button" class="notice-dismiss"><span class="screen-reader-text"></span></button>' );
    762761
    763762            // Ensure plain text.
    764             $button.find( '.screen-reader-text' ).text( btnText );
     763            $button.find( '.screen-reader-text' ).text( __( 'Dismiss this notice.' ) );
    765764            $button.on( 'click.wp-dismiss-notice', function( event ) {
    766765                event.preventDefault();
     
    15601559    $document.on( 'wp-menu-state-set wp-collapse-menu', function( event, eventData ) {
    15611560        var $collapseButton = $( '#collapse-button' ),
    1562             ariaExpanded = 'true',
    1563             ariaLabelText = commonL10n.collapseMenu;
     1561            ariaExpanded, ariaLabelText;
    15641562
    15651563        if ( 'folded' === eventData.state ) {
    15661564            ariaExpanded = 'false';
    1567             ariaLabelText = commonL10n.expandMenu;
     1565            ariaLabelText = __( 'Expand Main menu' );
     1566        } else {
     1567            ariaExpanded = 'true';
     1568            ariaLabelText = __( 'Collapse Main menu' );
    15681569        }
    15691570
  • trunk/src/wp-includes/script-loader.php

    r48266 r48267  
    609609
    610610    $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 );
    611     did_action( 'init' ) && $scripts->localize(
    612         'common',
    613         'commonL10n',
    614         array(
    615             'warnDelete'   => __( "You are about to permanently delete these items from your site.\nThis action cannot be undone.\n 'Cancel' to stop, 'OK' to delete." ),
    616             'dismiss'      => __( 'Dismiss this notice.' ),
    617             'collapseMenu' => __( 'Collapse Main menu' ),
    618             'expandMenu'   => __( 'Expand Main menu' ),
    619         )
    620     );
     611    $scripts->set_translations( 'common' );
    621612
    622613    $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );
     
    810801    // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
    811802    // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
    812     $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '4.1.4', 1 );
    813     $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '4.2.2', 1 );
     803    $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '3.2.0', 1 );
     804    $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '3.3.2', 1 );
    814805    $scripts->add( 'jquery-masonry', "/wp-includes/js/jquery/jquery.masonry$dev_suffix.js", array( 'jquery', 'masonry' ), '3.1.2b', 1 );
    815806
Note: See TracChangeset for help on using the changeset viewer.