I18N: Use `wp.i18n` for translatable strings in `wp-admin/js/set-post-thumbnail.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 #50605.
Built from https://develop.svn.wordpress.org/trunk@48396


git-svn-id: http://core.svn.wordpress.org/trunk@48165 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2020-07-07 18:55:04 +00:00
parent 0dc81cc24f
commit 4377e9a44e
8 changed files with 14 additions and 22 deletions

View File

@ -4,7 +4,7 @@
* @output wp-admin/js/post.js * @output wp-admin/js/post.js
*/ */
/* global ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */ /* global ajaxurl, wpAjax, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */
/* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */ /* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */
/* global WPSetThumbnailHTML, wptitlehint */ /* global WPSetThumbnailHTML, wptitlehint */
@ -145,7 +145,7 @@ window.wp = window.wp || {};
*/ */
function(str){ function(str){
if ( str == '0' ) { if ( str == '0' ) {
alert( setPostThumbnailL10n.error ); alert( __( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
} else { } else {
WPSetThumbnailHTML(str); WPSetThumbnailHTML(str);
} }

File diff suppressed because one or more lines are too long

View File

@ -2,23 +2,23 @@
* @output wp-admin/js/set-post-thumbnail.js * @output wp-admin/js/set-post-thumbnail.js
*/ */
/* global setPostThumbnailL10n, ajaxurl, post_id, alert */ /* global ajaxurl, post_id, alert */
/* exported WPSetAsThumbnail */ /* exported WPSetAsThumbnail */
window.WPSetAsThumbnail = function( id, nonce ) { window.WPSetAsThumbnail = function( id, nonce ) {
var $link = jQuery('a#wp-post-thumbnail-' + id); var $link = jQuery('a#wp-post-thumbnail-' + id);
$link.text( setPostThumbnailL10n.saving ); $link.text( wp.i18n.__( 'Saving…' ) );
jQuery.post(ajaxurl, { jQuery.post(ajaxurl, {
action: 'set-post-thumbnail', post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie ) action: 'set-post-thumbnail', post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
}, function(str){ }, function(str){
var win = window.dialogArguments || opener || parent || top; var win = window.dialogArguments || opener || parent || top;
$link.text( setPostThumbnailL10n.setThumbnail ); $link.text( wp.i18n.__( 'Use as featured image' ) );
if ( str == '0' ) { if ( str == '0' ) {
alert( setPostThumbnailL10n.error ); alert( wp.i18n.__( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
} else { } else {
jQuery('a.wp-post-thumbnail').show(); jQuery('a.wp-post-thumbnail').show();
$link.text( setPostThumbnailL10n.done ); $link.text( wp.i18n.__( 'Done' ) );
$link.fadeOut( 2000 ); $link.fadeOut( 2000 );
win.WPSetThumbnailID(id); win.WPSetThumbnailID(id);
win.WPSetThumbnailHTML(str); win.WPSetThumbnailHTML(str);

View File

@ -1,2 +1,2 @@
/*! This file is auto-generated */ /*! This file is auto-generated */
window.WPSetAsThumbnail=function(e,t){var o=jQuery("a#wp-post-thumbnail-"+e);o.text(setPostThumbnailL10n.saving),jQuery.post(ajaxurl,{action:"set-post-thumbnail",post_id:post_id,thumbnail_id:e,_ajax_nonce:t,cookie:encodeURIComponent(document.cookie)},function(t){var n=window.dialogArguments||opener||parent||top;o.text(setPostThumbnailL10n.setThumbnail),"0"==t?alert(setPostThumbnailL10n.error):(jQuery("a.wp-post-thumbnail").show(),o.text(setPostThumbnailL10n.done),o.fadeOut(2e3),n.WPSetThumbnailID(e),n.WPSetThumbnailHTML(t))})}; window.WPSetAsThumbnail=function(n,t){var a=jQuery("a#wp-post-thumbnail-"+n);a.text(wp.i18n.__("Saving\u2026")),jQuery.post(ajaxurl,{action:"set-post-thumbnail",post_id:post_id,thumbnail_id:n,_ajax_nonce:t,cookie:encodeURIComponent(document.cookie)},function(t){var e=window.dialogArguments||opener||parent||top;a.text(wp.i18n.__("Use as featured image")),"0"==t?alert(wp.i18n.__("Could not set that as the thumbnail image. Try a different attachment.")):(jQuery("a.wp-post-thumbnail").show(),a.text(wp.i18n.__("Done")),a.fadeOut(2e3),e.WPSetThumbnailID(n),e.WPSetThumbnailHTML(t))})};

View File

@ -627,7 +627,7 @@
_wpnonce: settings.post.nonce _wpnonce: settings.post.nonce
}).done( function( html ) { }).done( function( html ) {
if ( '0' === html ) { if ( '0' === html ) {
window.alert( window.setPostThumbnailL10n.error ); window.alert( wp.i18n.__( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
return; return;
} }
$( '.inside', '#postimagediv' ).html( html ); $( '.inside', '#postimagediv' ).html( html );

File diff suppressed because one or more lines are too long

View File

@ -1186,6 +1186,7 @@ function wp_default_scripts( $scripts ) {
$scripts->set_translations( 'media-views' ); $scripts->set_translations( 'media-views' );
$scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 ); $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );
$scripts->set_translations( 'media-editor' );
$scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 ); $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 );
$scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'jquery', 'media-views', 'media-audiovideo' ), false, 1 ); $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'jquery', 'media-views', 'media-audiovideo' ), false, 1 );
@ -1287,16 +1288,7 @@ function wp_default_scripts( $scripts ) {
$scripts->set_translations( 'image-edit' ); $scripts->set_translations( 'image-edit' );
$scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 ); $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 );
did_action( 'init' ) && $scripts->localize( $scripts->set_translations( 'set-post-thumbnail' );
'set-post-thumbnail',
'setPostThumbnailL10n',
array(
'setThumbnail' => __( 'Use as featured image' ),
'saving' => __( 'Saving...' ), // No ellipsis.
'error' => __( 'Could not set that as the thumbnail image. Try a different attachment.' ),
'done' => __( 'Done' ),
)
);
/* /*
* Navigation Menus: Adding underscore as a dependency to utilize _.debounce * Navigation Menus: Adding underscore as a dependency to utilize _.debounce

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-alpha-48395'; $wp_version = '5.5-alpha-48396';
/** /**
* 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.