Make WordPress Core

Changeset 48394


Ignore:
Timestamp:
07/07/2020 06:28:41 PM (6 years ago)
Author:
ocean90
Message:

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

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/lib/nav-menu.js

    r48168 r48394  
    1010 */
    1111
    12 /* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl, wpNavMenu */
     12/* global menus, postboxes, columns, isRtl, ajaxurl, wpNavMenu */
    1313
    1414(function($) {
    … …  
    589589                                        titleEl.text( title ).removeClass( 'no-title' );
    590590                                } else {
    591                                         titleEl.text( navMenuL10n.untitled ).addClass( 'no-title' );
     591                                        titleEl.text( wp.i18n._x( '(no label)', 'missing menu item navigation label' ) ).addClass( 'no-title' );
    592592                                }
    593593                        } );
    … …  
    10511051                                window.onbeforeunload = function(){
    10521052                                        if ( api.menusChanged )
    1053                                                 return navMenuL10n.saveAlert;
     1053                                                return wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
    10541054                                };
    10551055                        } else {
    … …  
    12211221                eventOnClickMenuDelete : function() {
    12221222                        // Delete warning AYS.
    1223                         if ( window.confirm( navMenuL10n.warnDeleteMenu ) ) {
     1223                        if ( window.confirm( wp.i18n.__( 'You are about to permanently delete this menu.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) {
    12241224                                window.onbeforeunload = null;
    12251225                                return true;
    … …  
    12541254
    12551255                        if( ! $items.length ) {
    1256                                 $('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' );
     1256                                $('.categorychecklist', panel).html( '<li><p>' + wp.i18n.__( 'No results found.' ) + '</p></li>' );
    12571257                                $( '.spinner', panel ).removeClass( 'is-active' );
    12581258                                wrapper.addClass( 'has-no-menu-item' );
  • trunk/src/wp-includes/script-loader.php

    r48392 r48394  
    13131313                 */
    13141314                $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox', 'json2', 'underscore' ) );
    1315                 did_action( 'init' ) && $scripts->localize(
    1316                         'nav-menu',
    1317                         'navMenuL10n',
    1318                         array(
    1319                                 'noResultsFound' => __( 'No results found.' ),
    1320                                 'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
    1321                                 'saveAlert'      => __( 'The changes you made will be lost if you navigate away from this page.' ),
    1322                                 'untitled'       => _x( '(no label)', 'missing menu item navigation label' ),
    1323                         )
    1324                 );
     1315                $scripts->set_translations( 'nav-menu' );
    13251316
    13261317                $scripts->add( 'custom-header', '/wp-admin/js/custom-header.js', array( 'jquery-masonry' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.