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.
Built from https://develop.svn.wordpress.org/trunk@48394


git-svn-id: http://core.svn.wordpress.org/trunk@48163 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2020-07-07 18:31:05 +00:00
parent ca1b6f324c
commit 291f3d76ec
4 changed files with 8 additions and 17 deletions

View File

@ -9,7 +9,7 @@
* @output wp-admin/js/nav-menu.js * @output wp-admin/js/nav-menu.js
*/ */
/* global menus, postboxes, columns, isRtl, navMenuL10n, ajaxurl, wpNavMenu */ /* global menus, postboxes, columns, isRtl, ajaxurl, wpNavMenu */
(function($) { (function($) {
@ -588,7 +588,7 @@
if ( title ) { if ( title ) {
titleEl.text( title ).removeClass( 'no-title' ); titleEl.text( title ).removeClass( 'no-title' );
} else { } else {
titleEl.text( navMenuL10n.untitled ).addClass( 'no-title' ); titleEl.text( wp.i18n._x( '(no label)', 'missing menu item navigation label' ) ).addClass( 'no-title' );
} }
} ); } );
}, },
@ -1050,7 +1050,7 @@
if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) { if ( 0 !== $('#menu-to-edit').length || 0 !== $('.menu-location-menus select').length ) {
window.onbeforeunload = function(){ window.onbeforeunload = function(){
if ( api.menusChanged ) if ( api.menusChanged )
return navMenuL10n.saveAlert; return wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
}; };
} else { } else {
// Make the post boxes read-only, as they can't be used yet. // Make the post boxes read-only, as they can't be used yet.
@ -1220,7 +1220,7 @@
eventOnClickMenuDelete : function() { eventOnClickMenuDelete : function() {
// Delete warning AYS. // Delete warning AYS.
if ( window.confirm( navMenuL10n.warnDeleteMenu ) ) { if ( window.confirm( wp.i18n.__( 'You are about to permanently delete this menu.\n\'Cancel\' to stop, \'OK\' to delete.' ) ) ) {
window.onbeforeunload = null; window.onbeforeunload = null;
return true; return true;
} }
@ -1253,7 +1253,7 @@
$item; $item;
if( ! $items.length ) { if( ! $items.length ) {
$('.categorychecklist', panel).html( '<li><p>' + navMenuL10n.noResultsFound + '</p></li>' ); $('.categorychecklist', panel).html( '<li><p>' + wp.i18n.__( 'No results found.' ) + '</p></li>' );
$( '.spinner', panel ).removeClass( 'is-active' ); $( '.spinner', panel ).removeClass( 'is-active' );
wrapper.addClass( 'has-no-menu-item' ); wrapper.addClass( 'has-no-menu-item' );
return; return;

File diff suppressed because one or more lines are too long

View File

@ -1312,16 +1312,7 @@ function wp_default_scripts( $scripts ) {
* see https://core.trac.wordpress.org/ticket/42321 * see https://core.trac.wordpress.org/ticket/42321
*/ */
$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' ) ); $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' ) );
did_action( 'init' ) && $scripts->localize( $scripts->set_translations( 'nav-menu' );
'nav-menu',
'navMenuL10n',
array(
'noResultsFound' => __( 'No results found.' ),
'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
'untitled' => _x( '(no label)', 'missing menu item navigation label' ),
)
);
$scripts->add( 'custom-header', '/wp-admin/js/custom-header.js', array( 'jquery-masonry' ), false, 1 ); $scripts->add( 'custom-header', '/wp-admin/js/custom-header.js', array( 'jquery-masonry' ), false, 1 );
$scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 ); $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-alpha-48393'; $wp_version = '5.5-alpha-48394';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.