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


git-svn-id: http://core.svn.wordpress.org/trunk@48154 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2020-07-07 16:49:05 +00:00
parent 964c506fb3
commit 2b32883f8b
4 changed files with 40 additions and 60 deletions

View File

@ -4,7 +4,7 @@
* @output wp-admin/js/post.js
*/
/* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */
/* global ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting, ClipboardJS */
/* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */
/* global WPSetThumbnailHTML, wptitlehint */
@ -15,7 +15,8 @@ window.makeSlugeditClickable = window.editPermalink = function(){};
window.wp = window.wp || {};
( function( $ ) {
var titleHasFocus = false;
var titleHasFocus = false,
__ = wp.i18n.__;
/**
* Control loading of comments on the post and term edit pages.
@ -73,11 +74,11 @@ window.wp = window.wp || {};
if ( commentsBox.st > commentsBox.total )
$('#show-comments').hide();
else
$('#show-comments').show().children('a').html(postL10n.showcomm);
$('#show-comments').show().children('a').text( __( 'Show more comments' ) );
return;
} else if ( 1 == r ) {
$('#show-comments').html(postL10n.endcomm);
$('#show-comments').text( __( 'No more comments found.' ) );
return;
}
@ -295,7 +296,6 @@ window.wp = window.wp || {};
*/
jQuery(document).ready( function($) {
var stamp, visibility, $submitButtons, updateVisibility, updateText,
sticky = '',
$textarea = $('#content'),
$document = $(document),
postId = $('#post_ID').val() || 0,
@ -307,7 +307,7 @@ jQuery(document).ready( function($) {
isMac = window.navigator.platform ? window.navigator.platform.indexOf( 'Mac' ) !== -1 : false,
copyAttachmentURLClipboard = new ClipboardJS( '.copy-attachment-url.edit-media' ),
copyAttachmentURLSuccessTimeout,
__ = wp.i18n.__;
__ = wp.i18n.__, _x = wp.i18n._x;
postboxes.add_postbox_toggles(pagenow);
@ -475,7 +475,7 @@ jQuery(document).ready( function($) {
$submitButtons.removeClass( 'disabled' );
}
}).on( 'before-autosave.edit-post', function() {
$( '.autosave-message' ).text( postL10n.savingText );
$( '.autosave-message' ).text( __( 'Saving Draft…' ) );
}).on( 'after-autosave.edit-post', function( event, data ) {
$( '.autosave-message' ).text( data.message );
@ -494,7 +494,7 @@ jQuery(document).ready( function($) {
if ( ( editor && ! editor.isHidden() && editor.isDirty() ) ||
( wp.autosave && wp.autosave.server.postChanged() ) ) {
return postL10n.saveAlert;
return __( 'The changes you made will be lost if you navigate away from this page.' );
}
}).on( 'unload.edit-post', function( event ) {
if ( ! releaseLock ) {
@ -754,14 +754,14 @@ jQuery(document).ready( function($) {
// Determine what the publish should be depending on the date and post status.
if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
publishOn = postL10n.publishOnFuture;
$('#publish').val( postL10n.schedule );
publishOn = __( 'Schedule for:' );
$('#publish').val( _x( 'Schedule', 'post action/button label' ) );
} else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
publishOn = postL10n.publishOn;
$('#publish').val( postL10n.publish );
publishOn = __( 'Publish on:' );
$('#publish').val( __( 'Publish' ) );
} else {
publishOn = postL10n.publishOnPast;
$('#publish').val( postL10n.update );
publishOn = __( 'Published on:' );
$('#publish').val( __( 'Update' ) );
}
// If the date is the same, set it to trigger update events.
@ -771,7 +771,8 @@ jQuery(document).ready( function($) {
} else {
$('#timestamp').html(
'\n' + publishOn + ' <b>' +
postL10n.dateFormat
// translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute.
__( '%1$s %2$s, %3$s at %4$s:%5$s' )
.replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
.replace( '%2$s', parseInt( jj, 10 ) )
.replace( '%3$s', aa )
@ -783,11 +784,11 @@ jQuery(document).ready( function($) {
// Add "privately published" to post status when applies.
if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) {
$('#publish').val( postL10n.update );
$('#publish').val( __( 'Update' ) );
if ( 0 === optPublish.length ) {
postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
postStatus.append('<option value="publish">' + __( 'Privately Published' ) + '</option>');
} else {
optPublish.html( postL10n.privatelyPublished );
optPublish.html( __( 'Privately Published' ) );
}
$('option[value="publish"]', postStatus).prop('selected', true);
$('#misc-publishing-actions .edit-post-status').hide();
@ -798,7 +799,7 @@ jQuery(document).ready( function($) {
postStatus.val($('#hidden_post_status').val());
}
} else {
optPublish.html( postL10n.published );
optPublish.html( __( 'Published' ) );
}
if ( postStatus.is(':hidden') )
$('#misc-publishing-actions .edit-post-status').show();
@ -816,9 +817,9 @@ jQuery(document).ready( function($) {
} else {
$('#save-post').show();
if ( $('option:selected', postStatus).val() == 'pending' ) {
$('#save-post').show().val( postL10n.savePending );
$('#save-post').show().val( __( 'Save as Pending' ) );
} else {
$('#save-post').show().val( postL10n.saveDraft );
$('#save-post').show().val( __( 'Save Draft' ) );
}
}
return true;
@ -850,21 +851,29 @@ jQuery(document).ready( function($) {
// Set the selected visibility as current.
$postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // Crazyhorse - multiple OK cancels.
var visibilityLabel = '', selectedVisibility = $postVisibilitySelect.find('input:radio:checked').val();
$postVisibilitySelect.slideUp('fast');
$('#visibility .edit-visibility').show().focus();
updateText();
if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
if ( 'public' !== selectedVisibility ) {
$('#sticky').prop('checked', false);
}
if ( $('#sticky').prop('checked') ) {
sticky = 'Sticky';
} else {
sticky = '';
switch ( selectedVisibility ) {
case 'public':
visibilityLabel = $( '#sticky' ).prop( 'checked' ) ? __( 'Public, Sticky' ) : __( 'Public' );
break;
case 'private':
visibilityLabel = __( 'Private' );
break;
case 'password':
visibilityLabel = __( 'Password Protected' );
break;
}
$('#post-visibility-display').html( postL10n[ $postVisibilitySelect.find('input:radio:checked').val() + sticky ] );
$('#post-visibility-display').text( visibilityLabel );
event.preventDefault();
});
@ -977,7 +986,7 @@ jQuery(document).ready( function($) {
$el = $( '#editable-post-name' );
revert_e = $el.html();
buttons.html( '<button type="button" class="save button button-small">' + postL10n.ok + '</button> <button type="button" class="cancel button-link">' + postL10n.cancel + '</button>' );
buttons.html( '<button type="button" class="save button button-small">' + __( 'OK' ) + '</button> <button type="button" class="cancel button-link">' + __( 'Cancel' ) + '</button>' );
// Save permalink changes.
buttons.children( '.save' ).click( function() {
@ -1010,7 +1019,7 @@ jQuery(document).ready( function($) {
permalink.html(permalinkOrig);
real_slug.val(new_slug);
$( '.edit-slug' ).focus();
wp.a11y.speak( postL10n.permalinkSaved );
wp.a11y.speak( __( 'Permalink saved' ) );
}
);
});

File diff suppressed because one or more lines are too long

View File

@ -1219,35 +1219,6 @@ function wp_default_scripts( $scripts ) {
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y', 'wp-sanitize', 'clipboard' ), false, 1 );
$scripts->set_translations( 'post' );
did_action( 'init' ) && $scripts->localize(
'post',
'postL10n',
array(
'ok' => __( 'OK' ),
'cancel' => __( 'Cancel' ),
'publishOn' => __( 'Publish on:' ),
'publishOnFuture' => __( 'Schedule for:' ),
'publishOnPast' => __( 'Published on:' ),
/* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */
'dateFormat' => __( '%1$s %2$s, %3$s at %4$s:%5$s' ),
'showcomm' => __( 'Show more comments' ),
'endcomm' => __( 'No more comments found.' ),
'publish' => __( 'Publish' ),
'schedule' => _x( 'Schedule', 'post action/button label' ),
'update' => __( 'Update' ),
'savePending' => __( 'Save as Pending' ),
'saveDraft' => __( 'Save Draft' ),
'private' => __( 'Private' ),
'public' => __( 'Public' ),
'publicSticky' => __( 'Public, Sticky' ),
'password' => __( 'Password Protected' ),
'privatelyPublished' => __( 'Privately Published' ),
'published' => __( 'Published' ),
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
'savingText' => __( 'Saving Draft&#8230;' ),
'permalinkSaved' => __( 'Permalink saved' ),
)
);
$scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery', 'underscore' ), false, 1 );

View File

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