mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 15:08:10 +01:00
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. Built from https://develop.svn.wordpress.org/trunk@48346 git-svn-id: http://core.svn.wordpress.org/trunk@48115 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
bc7de32645
commit
163e0ac228
@ -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() {
|
||||
|
2
wp-admin/js/theme-plugin-editor.min.js
vendored
2
wp-admin/js/theme-plugin-editor.min.js
vendored
File diff suppressed because one or more lines are too long
@ -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 );
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.5-alpha-48345';
|
||||
$wp_version = '5.5-alpha-48346';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user