Make WordPress Core

Changeset 48348


Ignore:
Timestamp:
07/06/2020 08:15:46 PM (5 years ago)
Author:
ocean90
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/edit-comments.js

    r48104 r48348  
    77 */
    88
    9 /* global adminCommentsL10n, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
     9/* global adminCommentsSettings, thousandsSeparator, list_args, QTags, ajaxurl, wpAjax */
    1010/* global commentReply, theExtraList, theList, setCommentsList */
    1111
     
    1414    updateHtmlTitle, updateDashboardText, updateInModerationText, adminTitle = document.title,
    1515    isDashboard = $('#dashboard_right_now').length,
    16     titleDiv, titleRegEx;
     16    titleDiv, titleRegEx,
     17    __ = wp.i18n.__;
    1718
    1819    /**
     
    192193        var newTitle, regExMatch, titleCount, commentFrag;
    193194
    194         titleRegEx = titleRegEx || new RegExp( adminCommentsL10n.docTitleCommentsCount.replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
     195        /* translators: %s: Comments count. */
     196        titleRegEx = titleRegEx || new RegExp( __( 'Comments (%s)' ).replace( '%s', '\\([0-9' + thousandsSeparator + ']+\\)' ) + '?' );
    195197        // Count funcs operate on a $'d element.
    196198        titleDiv = titleDiv || $( '<div />' );
     
    211213            regExMatch = titleRegEx.exec( document.title );
    212214            if ( regExMatch ) {
    213                 newTitle = document.title.replace( regExMatch[0], adminCommentsL10n.docTitleCommentsCount.replace( '%s', titleDiv.text() ) + ' ' );
     215                /* translators: %s: Comments count. */
     216                newTitle = document.title.replace( regExMatch[0], __( 'Comments (%s)' ).replace( '%s', titleDiv.text() ) + ' ' );
    214217            }
    215218        } else {
    216219            regExMatch = titleRegEx.exec( newTitle );
    217220            if ( regExMatch ) {
    218                 newTitle = newTitle.replace( regExMatch[0], adminCommentsL10n.docTitleComments );
     221                newTitle = newTitle.replace( regExMatch[0], __( 'Comments11' ) );
    219222            }
    220223        }
     
    361364        if ( c.is('.unapproved') ) {
    362365            if ( settings.data.id == replyID )
    363                 replyButton.text(adminCommentsL10n.replyApprove);
     366                replyButton.text( __( 'Approve and Reply' ) );
    364367
    365368            c.find( '.row-actions span.view' ).addClass( 'hidden' ).end()
     
    368371        } else {
    369372            if ( settings.data.id == replyID )
    370                 replyButton.text(adminCommentsL10n.reply);
     373                replyButton.text( __( 'Reply' ) );
    371374
    372375            c.find( '.row-actions span.view' ).removeClass( 'hidden' ).end()
     
    847850     */
    848851    toggle : function(el) {
    849         if ( 'none' !== $( el ).css( 'display' ) && ( $( '#replyrow' ).parent().is('#com-reply') || window.confirm( adminCommentsL10n.warnQuickEdit ) ) ) {
     852        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.' ) ) ) ) {
    850853            $( el ).find( 'button.vim-q' ).click();
    851854        }
     
    10081011
    10091012            if ( c.hasClass('unapproved') ) {
    1010                 replyButton.text(adminCommentsL10n.replyApprove);
     1013                replyButton.text( __( 'Approve and Reply' ) );
    10111014            } else {
    1012                 replyButton.text(adminCommentsL10n.reply);
     1015                replyButton.text( __( 'Reply' ) );
    10131016            }
    10141017
     
    12181221        }
    12191222
    1220         return window.confirm( adminCommentsL10n.warnCommentChanges );
     1223        return window.confirm( __( 'Are you sure you want to do this?\nThe comment changes you made will be lost.' ) );
    12211224    }
    12221225};
     
    13131316            ],
    13141317            {
    1315                 highlight_first: adminCommentsL10n.hotkeys_highlight_first,
    1316                 highlight_last: adminCommentsL10n.hotkeys_highlight_last,
     1318                highlight_first: adminCommentsSettings.hotkeys_highlight_first,
     1319                highlight_last: adminCommentsSettings.hotkeys_highlight_last,
    13171320                prev_page_link_cb: make_hotkeys_redirect('prev'),
    13181321                next_page_link_cb: make_hotkeys_redirect('next'),
  • trunk/src/wp-includes/script-loader.php

    r48347 r48348  
    11971197
    11981198        $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query' ), false, 1 );
     1199        $scripts->set_translations( 'admin-comments' );
    11991200        did_action( 'init' ) && $scripts->localize(
    12001201            'admin-comments',
    1201             'adminCommentsL10n',
     1202            'adminCommentsSettings',
    12021203            array(
    12031204                'hotkeys_highlight_first' => isset( $_GET['hotkeys_highlight_first'] ),
    12041205                'hotkeys_highlight_last'  => isset( $_GET['hotkeys_highlight_last'] ),
    1205                 'replyApprove'            => __( 'Approve and Reply' ),
    1206                 'reply'                   => __( 'Reply' ),
    1207                 'warnQuickEdit'           => __( "Are you sure you want to edit this comment?\nThe changes you made will be lost." ),
    1208                 'warnCommentChanges'      => __( "Are you sure you want to do this?\nThe comment changes you made will be lost." ),
    1209                 'docTitleComments'        => __( 'Comments' ),
    1210                 /* translators: %s: Comments count. */
    1211                 'docTitleCommentsCount'   => __( 'Comments (%s)' ),
    12121206            )
    12131207        );
Note: See TracChangeset for help on using the changeset viewer.