From b24fbd088becb00300be7c62106f0b5638c46d5f Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Tue, 7 Jul 2020 16:12:14 +0000 Subject: [PATCH] I18N: Use `wp.i18n` for translatable strings in `wp-admin/js/media.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 #50597. git-svn-id: https://develop.svn.wordpress.org/trunk@48384 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/admin/media.js | 6 +++--- src/wp-includes/script-loader.php | 8 +------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/js/_enqueues/admin/media.js b/src/js/_enqueues/admin/media.js index 8b603205f6..c992b5d3a4 100644 --- a/src/js/_enqueues/admin/media.js +++ b/src/js/_enqueues/admin/media.js @@ -10,7 +10,7 @@ * @requires jQuery */ -/* global ajaxurl, attachMediaBoxL10n, _wpMediaGridSettings, showNotice, findPosts */ +/* global ajaxurl, _wpMediaGridSettings, showNotice, findPosts */ ( function( $ ){ window.findPosts = { @@ -124,12 +124,12 @@ spinner.removeClass( 'is-active' ); }).done( function( x ) { if ( ! x.success ) { - $( '#find-posts-response' ).text( attachMediaBoxL10n.error ); + $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) ); } $( '#find-posts-response' ).html( x.data ); }).fail( function() { - $( '#find-posts-response' ).text( attachMediaBoxL10n.error ); + $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) ); }); } }; diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index bc762340ca..3ff287211a 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -1357,13 +1357,7 @@ function wp_default_scripts( $scripts ) { $scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 ); $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( - 'media', - 'attachMediaBoxL10n', - array( - 'error' => __( 'An error has occurred. Please reload the page and try again.' ), - ) - ); + $scripts->set_translations( 'media' ); $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array( 'jquery', 'jquery-ui-core', 'json2', 'imgareaselect', 'wp-a11y' ), false, 1 ); $scripts->set_translations( 'image-edit' );