I18N: Use wp.i18n for translatable strings in wp-admin/js/theme-plugin-editor.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.

Fixes #50576.

git-svn-id: https://develop.svn.wordpress.org/trunk@48346 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling
2020-07-06 19:33:54 +00:00
parent b84d8e4d09
commit 70cb267fde
2 changed files with 15 additions and 37 deletions

View File

@@ -1013,25 +1013,7 @@ function wp_default_scripts( $scripts ) {
$scripts->add( 'htmlhint-kses', '/wp-includes/js/codemirror/htmlhint-kses.js', array( 'htmlhint' ) );
$scripts->add( 'code-editor', "/wp-admin/js/code-editor$suffix.js", array( 'jquery', 'wp-codemirror', 'underscore' ) );
$scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ) );
did_action( 'init' ) && $scripts->add_inline_script(
'wp-theme-plugin-editor',
sprintf(
'wp.themePluginEditor.l10n = %s;',
wp_json_encode(
array(
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
'saveError' => __( 'Something went wrong. Your change may not have been saved. Please try again. There is also a chance that you may need to manually fix and upload the file over FTP.' ),
'lintError' => array(
/* translators: %d: Error count. */
'singular' => _n( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.', 1 ),
/* translators: %d: Error count. */
'plural' => _n( 'There is %d error which must be fixed before you can update this file.', 'There are %d errors which must be fixed before you can update this file.', 2 ),
// @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
),
)
)
)
);
$scripts->set_translations( 'wp-theme-plugin-editor' );
$scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 );