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
This commit is contained in:
Sergey Biryukov 2020-07-02 11:09:23 +00:00
parent 6cc0063ba6
commit 5714ef31c0
2 changed files with 21 additions and 28 deletions

View File

@ -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' );

View File

@ -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' );