diff --git a/src/js/_enqueues/wp/theme-plugin-editor.js b/src/js/_enqueues/wp/theme-plugin-editor.js index 84695dfefa..71fd3c1811 100644 --- a/src/js/_enqueues/wp/theme-plugin-editor.js +++ b/src/js/_enqueues/wp/theme-plugin-editor.js @@ -10,17 +10,10 @@ if ( ! window.wp ) { wp.themePluginEditor = (function( $ ) { 'use strict'; - var component, TreeLinks; + var component, TreeLinks, + __ = wp.i18n.__, _n = wp.i18n._n, sprintf = wp.i18n.sprintf; component = { - l10n: { - lintError: { - singular: '', - plural: '' - }, - saveAlert: '', - saveError: '' - }, codeEditor: {}, instance: null, noticeElements: {}, @@ -75,7 +68,7 @@ wp.themePluginEditor = (function( $ ) { $( window ).on( 'beforeunload', function() { if ( component.dirty ) { - return component.l10n.saveAlert; + return __( 'The changes you made will be lost if you navigate away from this page.' ); } return undefined; } ); @@ -233,7 +226,7 @@ wp.themePluginEditor = (function( $ ) { var notice = $.extend( { code: 'save_error', - message: component.l10n.saveError + message: __( '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.' ) }, response, { @@ -375,20 +368,23 @@ wp.themePluginEditor = (function( $ ) { * @return {void} */ codeEditorSettings.onUpdateErrorNotice = function onUpdateErrorNotice( errorAnnotations ) { - var message, noticeElement; + var noticeElement; component.submitButton.toggleClass( 'disabled', errorAnnotations.length > 0 ); if ( 0 !== errorAnnotations.length ) { - if ( 1 === errorAnnotations.length ) { - message = component.l10n.lintError.singular.replace( '%d', '1' ); - } else { - message = component.l10n.lintError.plural.replace( '%d', String( errorAnnotations.length ) ); - } noticeElement = component.addNotice({ code: 'lint_errors', type: 'error', - message: message, + message: sprintf( + /* translators: %s: Error count. */ + _n( + 'There is %s error which must be fixed before you can update this file.', + 'There are %s errors which must be fixed before you can update this file.', + errorAnnotations.length + ), + String( errorAnnotations.length ) + ), dismissible: false }); noticeElement.find( 'input[type=checkbox]' ).on( 'click', function() { diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 1b44067c8a..7ebb7e3a43 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -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 );