Make WordPress Core

Changeset 48346


Ignore:
Timestamp:
07/06/2020 07:33:54 PM (6 years ago)
Author:
ocean90
Message:

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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/theme-plugin-editor.js

    r47122 r48346  
    1111wp.themePluginEditor = (function( $ ) {
    1212        'use strict';
    13         var component, TreeLinks;
     13        var component, TreeLinks,
     14                __ = wp.i18n.__, _n = wp.i18n._n, sprintf = wp.i18n.sprintf;
    1415
    1516        component = {
    16                 l10n: {
    17                         lintError: {
    18                                 singular: '',
    19                                 plural: ''
    20                         },
    21                         saveAlert: '',
    22                         saveError: ''
    23                 },
    2417                codeEditor: {},
    2518                instance: null,
    … …  
    7669                $( window ).on( 'beforeunload', function() {
    7770                        if ( component.dirty ) {
    78                                 return component.l10n.saveAlert;
     71                                return __( 'The changes you made will be lost if you navigate away from this page.' );
    7972                        }
    8073                        return undefined;
    … …  
    234227                                {
    235228                                        code: 'save_error',
    236                                         message: component.l10n.saveError
     229                                        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.' )
    237230                                },
    238231                                response,
    … …  
    376369                 */
    377370                codeEditorSettings.onUpdateErrorNotice = function onUpdateErrorNotice( errorAnnotations ) {
    378                         var message, noticeElement;
     371                        var noticeElement;
    379372
    380373                        component.submitButton.toggleClass( 'disabled', errorAnnotations.length > 0 );
    381374
    382375                        if ( 0 !== errorAnnotations.length ) {
    383                                 if ( 1 === errorAnnotations.length ) {
    384                                         message = component.l10n.lintError.singular.replace( '%d', '1' );
    385                                 } else {
    386                                         message = component.l10n.lintError.plural.replace( '%d', String( errorAnnotations.length ) );
    387                                 }
    388376                                noticeElement = component.addNotice({
    389377                                        code: 'lint_errors',
    390378                                        type: 'error',
    391                                         message: message,
     379                                        message: sprintf(
     380                                                /* translators: %s: Error count. */
     381                                                _n(
     382                                                        'There is %s error which must be fixed before you can update this file.',
     383                                                        'There are %s errors which must be fixed before you can update this file.',
     384                                                        errorAnnotations.length
     385                                                ),
     386                                                String( errorAnnotations.length )
     387                                        ),
    392388                                        dismissible: false
    393389                                });
  • trunk/src/wp-includes/script-loader.php

    r48340 r48346  
    10141014        $scripts->add( 'code-editor', "/wp-admin/js/code-editor$suffix.js", array( 'jquery', 'wp-codemirror', 'underscore' ) );
    10151015        $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' ) );
    1016         did_action( 'init' ) && $scripts->add_inline_script(
    1017                 'wp-theme-plugin-editor',
    1018                 sprintf(
    1019                         'wp.themePluginEditor.l10n = %s;',
    1020                         wp_json_encode(
    1021                                 array(
    1022                                         'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
    1023                                         '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.' ),
    1024                                         'lintError' => array(
    1025                                                 /* translators: %d: Error count. */
    1026                                                 '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 ),
    1027                                                 /* translators: %d: Error count. */
    1028                                                 '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 ),
    1029                                                 // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
    1030                                         ),
    1031                                 )
    1032                         )
    1033                 )
    1034         );
     1016        $scripts->set_translations( 'wp-theme-plugin-editor' );
    10351017
    10361018        $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.