I18N: Use wp.i18n
for translatable strings in wp-admin/js/widgets.js
.
This removes the usage of `$scripts->add_inline_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. Fixes #50600. git-svn-id: https://develop.svn.wordpress.org/trunk@48387 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7377c28728
commit
8c42273b7a
@ -15,20 +15,6 @@ window.wpWidgets = {
|
|||||||
*/
|
*/
|
||||||
hoveredSidebar: null,
|
hoveredSidebar: null,
|
||||||
|
|
||||||
/**
|
|
||||||
* Translations.
|
|
||||||
*
|
|
||||||
* Exported from PHP in wp_default_scripts().
|
|
||||||
*
|
|
||||||
* @var {object}
|
|
||||||
*/
|
|
||||||
l10n: {
|
|
||||||
save: '{save}',
|
|
||||||
saved: '{saved}',
|
|
||||||
saveAlert: '{saveAlert}',
|
|
||||||
widgetAdded: '{widgetAdded}'
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lookup of which widgets have had change events triggered.
|
* Lookup of which widgets have had change events triggered.
|
||||||
*
|
*
|
||||||
@ -109,7 +95,7 @@ window.wpWidgets = {
|
|||||||
$( this ).find( '.widget-inside :tabbable:first' ).focus();
|
$( this ).find( '.widget-inside :tabbable:first' ).focus();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
event.returnValue = wpWidgets.l10n.saveAlert;
|
event.returnValue = wp.i18n.__( 'The changes you made will be lost if you navigate away from this page.' );
|
||||||
return event.returnValue;
|
return event.returnValue;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -141,11 +127,11 @@ window.wpWidgets = {
|
|||||||
// Save button is initially disabled, but is enabled when a field is changed.
|
// Save button is initially disabled, but is enabled when a field is changed.
|
||||||
if ( ! widget.data( 'dirty-state-initialized' ) ) {
|
if ( ! widget.data( 'dirty-state-initialized' ) ) {
|
||||||
saveButton = inside.find( '.widget-control-save' );
|
saveButton = inside.find( '.widget-control-save' );
|
||||||
saveButton.prop( 'disabled', true ).val( wpWidgets.l10n.saved );
|
saveButton.prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
|
||||||
inside.on( 'input change', function() {
|
inside.on( 'input change', function() {
|
||||||
self.dirtyWidgets[ widgetId ] = true;
|
self.dirtyWidgets[ widgetId ] = true;
|
||||||
widget.addClass( 'widget-dirty' );
|
widget.addClass( 'widget-dirty' );
|
||||||
saveButton.prop( 'disabled', false ).val( wpWidgets.l10n.save );
|
saveButton.prop( 'disabled', false ).val( wp.i18n.__( 'Save' ) );
|
||||||
});
|
});
|
||||||
widget.data( 'dirty-state-initialized', true );
|
widget.data( 'dirty-state-initialized', true );
|
||||||
}
|
}
|
||||||
@ -586,7 +572,7 @@ window.wpWidgets = {
|
|||||||
wpWidgets.appendTitle( widget );
|
wpWidgets.appendTitle( widget );
|
||||||
|
|
||||||
// Re-disable the save button.
|
// Re-disable the save button.
|
||||||
widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wpWidgets.l10n.saved );
|
widget.find( '.widget-control-save' ).prop( 'disabled', true ).val( wp.i18n.__( 'Saved' ) );
|
||||||
|
|
||||||
widget.removeClass( 'widget-dirty' );
|
widget.removeClass( 'widget-dirty' );
|
||||||
|
|
||||||
@ -717,7 +703,7 @@ window.wpWidgets = {
|
|||||||
// have to queue this "by hand".
|
// have to queue this "by hand".
|
||||||
widget.find( '.widget-title' ).trigger('click');
|
widget.find( '.widget-title' ).trigger('click');
|
||||||
// At the end of the animation, announce the widget has been added.
|
// At the end of the animation, announce the widget has been added.
|
||||||
window.wp.a11y.speak( wpWidgets.l10n.widgetAdded, 'assertive' );
|
window.wp.a11y.speak( wp.i18n.__( 'Widget has been added to the selected sidebar' ), 'assertive' );
|
||||||
}, 250 );
|
}, 250 );
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1239,20 +1239,7 @@ function wp_default_scripts( $scripts ) {
|
|||||||
$scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ) );
|
$scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ) );
|
||||||
|
|
||||||
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-a11y' ), false, 1 );
|
$scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-a11y' ), false, 1 );
|
||||||
did_action( 'init' ) && $scripts->add_inline_script(
|
$scripts->set_translations( 'admin-widgets' );
|
||||||
'admin-widgets',
|
|
||||||
sprintf(
|
|
||||||
'wpWidgets.l10n = %s;',
|
|
||||||
wp_json_encode(
|
|
||||||
array(
|
|
||||||
'save' => __( 'Save' ),
|
|
||||||
'saved' => __( 'Saved' ),
|
|
||||||
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
|
|
||||||
'widgetAdded' => __( 'Widget has been added to the selected sidebar' ),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) );
|
$scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) );
|
||||||
$scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' );
|
$scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' );
|
||||||
|
Loading…
Reference in New Issue
Block a user