Make WordPress Core

Changeset 48384


Ignore:
Timestamp:
07/07/2020 04:12:14 PM (6 years ago)
Author:
ocean90
Message:

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

Props swissspidy, ocean90.
See #20491.
Fixes #50597.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/admin/media.js

    r47807 r48384  
    1111 */
    1212
    13 /* global ajaxurl, attachMediaBoxL10n, _wpMediaGridSettings, showNotice, findPosts */
     13/* global ajaxurl, _wpMediaGridSettings, showNotice, findPosts */
    1414
    1515( function( $ ){
    … …  
    125125                        }).done( function( x ) {
    126126                                if ( ! x.success ) {
    127                                         $( '#find-posts-response' ).text( attachMediaBoxL10n.error );
     127                                        $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) );
    128128                                }
    129129
    130130                                $( '#find-posts-response' ).html( x.data );
    131131                        }).fail( function() {
    132                                 $( '#find-posts-response' ).text( attachMediaBoxL10n.error );
     132                                $( '#find-posts-response' ).text( wp.i18n.__( 'An error has occurred. Please reload the page and try again.' ) );
    133133                        });
    134134                }
  • trunk/src/wp-includes/script-loader.php

    r48383 r48384  
    13581358                $scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 );
    13591359                $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery' ), false, 1 );
    1360                 did_action( 'init' ) && $scripts->localize(
    1361                         'media',
    1362                         'attachMediaBoxL10n',
    1363                         array(
    1364                                 'error' => __( 'An error has occurred. Please reload the page and try again.' ),
    1365                         )
    1366                 );
     1360                $scripts->set_translations( 'media' );
    13671361
    13681362                $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array( 'jquery', 'jquery-ui-core', 'json2', 'imgareaselect', 'wp-a11y' ), false, 1 );
Note: See TracChangeset for help on using the changeset viewer.