I18N: Use `wp.i18n` for translatable strings in `wp-admin/js/edit-comments.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 #50578.
Built from https://develop.svn.wordpress.org/trunk@48348


git-svn-id: http://core.svn.wordpress.org/trunk@48117 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2020-07-06 20:17:02 +00:00
parent 31d93c553a
commit 1145607a85
4 changed files with 20 additions and 23 deletions

View File

@ -6,14 +6,15 @@
* @output wp-admin/js/edit-comments.js
*/
/* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
/* global adminCommentsSettings, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
/* global commentReply, theExtraList, theList, setCommentsList */
(function($) {
var getCount, updateCount, updateCountText, updatePending, updateApproved,
updateHtmlTitle, updateDashboardText, updateInModerationText, adminTitle = document.title,
isDashboard = $('#dashboard_right_now').length,
titleDiv, titleRegEx;
titleDiv, titleRegEx,
__ = wp.i18n.__;
/**
* Extracts a number from the content of a jQuery element.
@ -191,7 +192,8 @@ var getCount, updateCount, updateCountText, updatePending, updateApproved,
updateHtmlTitle = function( diff ) {
var newTitle, regExMatch, titleCount, commentFrag;
titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
/* translators: %s: Comments count. */
titleRegEx = titleRegEx || new RegExp( __( 'Comments (%s)' ).replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
// Count funcs operate on a $'d element.
titleDiv = titleDiv || $( '<div />' );
newTitle = adminTitle;
@ -210,12 +212,13 @@ var getCount, updateCount, updateCountText, updatePending, updateApproved,
updateCount( titleDiv, titleCount );
regExMatch = titleRegEx.exec( document.title );
if ( regExMatch ) {
newTitle = document.title.replace( regExMatch[0], adminCommentsL10n.docTitleCommentsCount.replace( '%s', titleDiv.text() ) + ' ' );
/* translators: %s: Comments count. */
newTitle = document.title.replace( regExMatch[0], __( 'Comments (%s)' ).replace( '%s', titleDiv.text() ) + ' ' );
}
} else {
regExMatch = titleRegEx.exec( newTitle );
if ( regExMatch ) {
newTitle = newTitle.replace( regExMatch[0], adminCommentsL10n.docTitleComments );
newTitle = newTitle.replace( regExMatch[0], __( 'Comments11' ) );
}
}
document.title = newTitle;
@ -360,14 +363,14 @@ window.setCommentsList = function() {
if ( c.is('.unapproved') ) {
if ( settings.data.id == replyID )
replyButton.text(adminCommentsL10n.replyApprove);
replyButton.text( __( 'Approve and Reply' ) );
c.find( '.row-actions span.view' ).addClass( 'hidden' ).end()
.find( 'div.comment_status' ).html( '0' );
} else {
if ( settings.data.id == replyID )
replyButton.text(adminCommentsL10n.reply);
replyButton.text( __( 'Reply' ) );
c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end()
.find( 'div.comment_status' ).html( '1' );
@ -846,7 +849,7 @@ window.commentReply = {
* @return {void}
*/
toggle : function(el) {
if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( adminCommentsL10n.warnQuickEdit ) ) ) {
if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( __( 'Are you sure you want to edit this comment?\nThe changes you made will be lost.' ) ) ) ) {
$( el ).find( 'button.vim-q' ).click();
}
},
@ -1007,9 +1010,9 @@ window.commentReply = {
c.after(editRow);
if ( c.hasClass('unapproved') ) {
replyButton.text(adminCommentsL10n.replyApprove);
replyButton.text( __( 'Approve and Reply' ) );
} else {
replyButton.text(adminCommentsL10n.reply);
replyButton.text( __( 'Reply' ) );
}
$('#replyrow').fadeIn(300, function(){ $(this).show(); });
@ -1217,7 +1220,7 @@ window.commentReply = {
return true;
}
return window.confirm( adminCommentsL10n.warnCommentChanges );
return window.confirm( __( 'Are you sure you want to do this?\nThe comment changes you made will be lost.' ) );
}
};
@ -1312,8 +1315,8 @@ $(document).ready(function(){
['shift+u', make_bulk('unapprove')]
],
{
highlight_first: adminCommentsL10n.hotkeys_highlight_first,
highlight_last: adminCommentsL10n.hotkeys_highlight_last,
highlight_first: adminCommentsSettings.hotkeys_highlight_first,
highlight_last: adminCommentsSettings.hotkeys_highlight_last,
prev_page_link_cb: make_hotkeys_redirect('prev'),
next_page_link_cb: make_hotkeys_redirect('next'),
hotkeys_opts: {

File diff suppressed because one or more lines are too long

View File

@ -1196,19 +1196,13 @@ function wp_default_scripts( $scripts ) {
$scripts->set_translations( 'admin-tags' );
$scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query' ), false, 1 );
$scripts->set_translations( 'admin-comments' );
did_action( 'init' ) && $scripts->localize(
'admin-comments',
'adminCommentsL10n',
'adminCommentsSettings',
array(
'hotkeys_highlight_first' => isset( $_GET['hotkeys_highlight_first'] ),
'hotkeys_highlight_last' => isset( $_GET['hotkeys_highlight_last'] ),
'replyApprove' => __( 'Approve and Reply' ),
'reply' => __( 'Reply' ),
'warnQuickEdit' => __( "Are you sure you want to edit this comment?\nThe changes you made will be lost." ),
'warnCommentChanges' => __( "Are you sure you want to do this?\nThe comment changes you made will be lost." ),
'docTitleComments' => __( 'Comments' ),
/* translators: %s: Comments count. */
'docTitleCommentsCount' => __( 'Comments (%s)' ),
)
);

View File

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