Make WordPress Core

Changeset 57654


Ignore:
Timestamp:
02/18/2024 10:14:04 PM (2 months ago)
Author:
peterwilsoncc
Message:

Script Loader: Switch to JavaScript translations.

Update JavaScript files for tag suggestions and the TinyMCE link plugin to use client side translations. This allows for _n() to be used for strings requiring singular and plural versions in which the correct form is only known client side.

Props audrasjb, chaion07, costdev, hellofromtonya, johnbillion, marybaum, nicolefurlan, oglekler, rebasaurus, rsiddharth, sergeybiryukov, shaampk1, shahariaazam, swissspidy, tobifjellner.
Fixes #48244.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r57022 r57654  
    353353
    354354window.setPostThumbnailL10n = deprecateL10nObject( 'setPostThumbnailL10n', window.setPostThumbnailL10n, '5.5.0' );
     355
     356/**
     357 * Removed in 6.5.0, needed for back-compatibility.
     358 *
     359 * @since 4.5.0
     360 * @deprecated 6.5.0
     361 */
     362window.uiAutocompleteL10n = window.uiAutocompleteL10n || {
     363    noResults: '',
     364    oneResult: '',
     365    manyResults: '',
     366    itemSelected: ''
     367};
     368
     369window.uiAutocompleteL10n = deprecateL10nObject( 'uiAutocompleteL10n', window.uiAutocompleteL10n, '6.5.0' );
    355370
    356371/**
  • trunk/src/js/_enqueues/admin/tags-suggest.js

    r53089 r57654  
    55 */
    66( function( $ ) {
    7     if ( typeof window.uiAutocompleteL10n === 'undefined' ) {
    8         return;
    9     }
    10 
    117    var tempID = 0;
    128    var separator = wp.i18n._x( ',', 'tag delimiter' ) || ',';
     9    var __ = wp.i18n.__,
     10        _n = wp.i18n._n,
     11        sprintf = wp.i18n.sprintf;
    1312
    1413    function split( val ) {
     
    140139            },
    141140            messages: {
    142                 noResults: window.uiAutocompleteL10n.noResults,
     141                noResults: __( 'No results found.' ),
    143142                results: function( number ) {
    144                     if ( number > 1 ) {
    145                         return window.uiAutocompleteL10n.manyResults.replace( '%d', number );
    146                     }
    147 
    148                     return window.uiAutocompleteL10n.oneResult;
     143                    return sprintf(
     144                        /* translators: %d: Number of search results found. */
     145                        _n(
     146                            '%d result found. Use up and down arrow keys to navigate.',
     147                            '%d results found. Use up and down arrow keys to navigate.',
     148                            number
     149                        ),
     150                        number
     151                    );
    149152                }
    150153            }
  • trunk/src/js/_enqueues/vendor/tinymce/plugins/wplink/plugin.js

    r47122 r57654  
    9999        var speak = ( typeof window.wp !== 'undefined' && window.wp.a11y && window.wp.a11y.speak ) ? window.wp.a11y.speak : function() {};
    100100        var hasLinkError = false;
     101        var __ = window.wp.i18n.__;
     102        var _n = window.wp.i18n._n;
     103        var sprintf = window.wp.i18n.sprintf;
    101104
    102105        function getSelectedLink() {
     
    458461                        },
    459462                        messages: {
    460                             noResults: ( typeof window.uiAutocompleteL10n !== 'undefined' ) ? window.uiAutocompleteL10n.noResults : '',
     463                            noResults: __( 'No results found.' ) ,
    461464                            results: function( number ) {
    462                                 if ( typeof window.uiAutocompleteL10n !== 'undefined' ) {
    463                                     if ( number > 1 ) {
    464                                         return window.uiAutocompleteL10n.manyResults.replace( '%d', number );
    465                                     }
    466 
    467                                     return window.uiAutocompleteL10n.oneResult;
    468                                 }
     465                                return sprintf(
     466                                    /* translators: %d: Number of search results found. */
     467                                    _n(
     468                                        '%d result found. Use up and down arrow keys to navigate.',
     469                                        '%d results found. Use up and down arrow keys to navigate.',
     470                                        number
     471                                    ),
     472                                    number
     473                                );
    469474                            }
    470475                        }
  • trunk/src/wp-includes/script-loader.php

    r57602 r57654  
    932932    $scripts->add( 'jquery-ui-position', false, array( 'jquery-ui-core' ), '1.13.2', 1 );
    933933    $scripts->add( 'jquery-ui-widget', false, array( 'jquery-ui-core' ), '1.13.2', 1 );
    934 
    935     // Strings for 'jquery-ui-autocomplete' live region messages.
    936     did_action( 'init' ) && $scripts->localize(
    937         'jquery-ui-autocomplete',
    938         'uiAutocompleteL10n',
    939         array(
    940             'noResults'    => __( 'No results found.' ),
    941             /* translators: Number of results found when using jQuery UI Autocomplete. */
    942             'oneResult'    => __( '1 result found. Use up and down arrow keys to navigate.' ),
    943             /* translators: %d: Number of results found when using jQuery UI Autocomplete. */
    944             'manyResults'  => __( '%d results found. Use up and down arrow keys to navigate.' ),
    945             'itemSelected' => __( 'Item selected.' ),
    946         )
    947     );
    948934
    949935    // Deprecated, not used in core, most functionality is included in jQuery 1.3.
     
    12481234    $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array( 'hoverintent-js' ), false, 1 );
    12491235
    1250     $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
     1236    $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'common', 'jquery', 'wp-a11y', 'wp-i18n' ), false, 1 );
     1237    $scripts->set_translations( 'wplink' );
    12511238    did_action( 'init' ) && $scripts->localize(
    12521239        'wplink',
     
    14261413        $scripts->set_translations( 'tags-box' );
    14271414
    1428         $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 );
     1415        $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'common', 'jquery-ui-autocomplete', 'wp-a11y', 'wp-i18n' ), false, 1 );
    14291416        $scripts->set_translations( 'tags-suggest' );
    14301417
Note: See TracChangeset for help on using the changeset viewer.