From 5714ef31c0b66e6170c02be8e7b55e93230a46af Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 2 Jul 2020 11:09:23 +0000 Subject: [PATCH] I18N: Use `wp.i18n` for translatable strings in `wp-admin/js/privacy-tools.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, afercia. See #20491. Fixes #50535. git-svn-id: https://develop.svn.wordpress.org/trunk@48274 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/admin/privacy-tools.js | 27 +++++++++++++++---------- src/wp-includes/script-loader.php | 22 +++++--------------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/js/_enqueues/admin/privacy-tools.js b/src/js/_enqueues/admin/privacy-tools.js index 12b0722ddb..a8f4f4ccde 100644 --- a/src/js/_enqueues/admin/privacy-tools.js +++ b/src/js/_enqueues/admin/privacy-tools.js @@ -6,7 +6,7 @@ // Privacy request action handling. jQuery( document ).ready( function( $ ) { - var strings = window.privacyToolsL10n || {}, + var __ = wp.i18n.__, copiedNoticeTimeout; function setActionState( $action, state ) { @@ -77,7 +77,7 @@ jQuery( document ).ready( function( $ ) { setExportProgress( 0 ); function onExportDoneSuccess( zipUrl ) { - var summaryMessage = strings.emailSent; + var summaryMessage = __( 'The personal data export link for this user was sent.' ); setActionState( $action, 'export-personal-data-success' ); @@ -86,16 +86,19 @@ jQuery( document ).ready( function( $ ) { if ( 'undefined' !== typeof zipUrl ) { window.location = zipUrl; } else if ( ! sendAsEmail ) { - onExportFailure( strings.noExportFile ); + onExportFailure( __( 'No personal data export file was generated.' ) ); } setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 ); } function onExportFailure( errorMessage ) { + var summaryMessage = __( 'An error occurred while attempting to export personal data.' ); + setActionState( $action, 'export-personal-data-failed' ); + if ( errorMessage ) { - appendResultsAfterRow( $requestRow, 'notice-error', strings.exportError, [ errorMessage ] ); + appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [ errorMessage ] ); } setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 ); @@ -175,23 +178,23 @@ jQuery( document ).ready( function( $ ) { setErasureProgress( 0 ); function onErasureDoneSuccess() { - var summaryMessage = strings.noDataFound, + var summaryMessage = __( 'No personal data was found for this user.' ), classes = 'notice-success'; setActionState( $action, 'remove-personal-data-success' ); if ( false === hasRemoved ) { if ( false === hasRetained ) { - summaryMessage = strings.noDataFound; + summaryMessage = __( 'No personal data was found for this user.' ); } else { - summaryMessage = strings.noneRemoved; + summaryMessage = __( 'Personal data was found for this user but was not erased.' ); classes = 'notice-warning'; } } else { if ( false === hasRetained ) { - summaryMessage = strings.foundAndRemoved; + summaryMessage = __( 'All of the personal data found for this user was erased.' ); } else { - summaryMessage = strings.someNotRemoved; + summaryMessage = __( 'Personal data was found for this user but some of the personal data found was not erased.' ); classes = 'notice-warning'; } } @@ -201,8 +204,11 @@ jQuery( document ).ready( function( $ ) { } function onErasureFailure() { + var summaryMessage = __( 'An error occurred while attempting to find and erase personal data.' ); + setActionState( $action, 'remove-personal-data-failed' ); - appendResultsAfterRow( $requestRow, 'notice-error', strings.removalError, [] ); + + appendResultsAfterRow( $requestRow, 'notice-error', summaryMessage, [] ); setTimeout( function() { $rowActions.removeClass( 'processing' ); }, 500 ); } @@ -267,7 +273,6 @@ jQuery( document ).ready( function( $ ) { var $parent, $container, range, - __ = wp.i18n.__, $target = $( event.target ), copiedNotice = $target.siblings( '.success' ); diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index f016a1728d..8984428062 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -1205,8 +1205,9 @@ function wp_default_scripts( $scripts ) { // To enqueue media-views or media-editor, call wp_enqueue_media(). // Both rely on numerous settings, styles, and templates to operate correctly. - $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request', 'wp-a11y', 'wp-i18n', 'clipboard' ), false, 1 ); + $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request', 'wp-a11y', 'clipboard' ), false, 1 ); $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-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 ); @@ -1379,24 +1380,11 @@ function wp_default_scripts( $scripts ) { ) ); - $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y', 'wp-i18n' ), false, 1 ); + $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y' ), false, 1 ); $scripts->set_translations( 'site-health' ); - $scripts->add( 'privacy-tools', "/wp-admin/js/privacy-tools$suffix.js", array( 'jquery', 'wp-a11y', 'wp-i18n' ), false, 1 ); - did_action( 'init' ) && $scripts->localize( - 'privacy-tools', - 'privacyToolsL10n', - array( - 'noDataFound' => __( 'No personal data was found for this user.' ), - 'foundAndRemoved' => __( 'All of the personal data found for this user was erased.' ), - 'noneRemoved' => __( 'Personal data was found for this user but was not erased.' ), - 'someNotRemoved' => __( 'Personal data was found for this user but some of the personal data found was not erased.' ), - 'removalError' => __( 'An error occurred while attempting to find and erase personal data.' ), - 'emailSent' => __( 'The personal data export link for this user was sent.' ), - 'noExportFile' => __( 'No personal data export file was generated.' ), - 'exportError' => __( 'An error occurred while attempting to export personal data.' ), - ) - ); + $scripts->add( 'privacy-tools', "/wp-admin/js/privacy-tools$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 ); + $scripts->set_translations( 'privacy-tools' ); $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize' ), false, 1 ); $scripts->set_translations( 'updates' );