Make WordPress Core

Changeset 49151


Ignore:
Timestamp:
10/14/2020 09:11:09 PM (4 years ago)
Author:
ocean90
Message:

I18N: Use wp.i18n for translatable strings in wp-admin/js/dashboard.js.

  • Deprecate the l10n property on communityEventsData.
  • Introduce version parameter for deprecateL10nObject and backfill the version for deprecated objects in 5.5.0.
  • Add a noop version of deprecateL10nObject for QUnit testing.

Fixes #51498.

Location:
trunk
Files:
1 added
7 edited

Legend:

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

    r49142 r49151  
    5656 *
    5757 * @since 5.5.1
     58 * @since 5.6.0 Added the `version` parameter.
    5859 *
    5960 * @param {string} name       The name of the object, i.e. commonL10n.
    6061 * @param {object} l10nObject The object to deprecate the properties on.
     62 * @param {string} version    The version of WordPress that deprecated the property.
    6163 *
    6264 * @return {object} The object with all its properties deprecated.
    6365 */
    64 function deprecateL10nObject( name, l10nObject ) {
     66function deprecateL10nObject( name, l10nObject, version ) {
    6567    var deprecatedObject = {};
    6668
     
    7173        if ( 'object' === typeof prop ) {
    7274            Object.defineProperty( deprecatedObject, key, { get: function() {
    73                 deprecatedProperty( propName, '5.5.0', prop.alternative );
     75                deprecatedProperty( propName, version, prop.alternative );
    7476                return prop.func();
    7577            } } );
    7678        } else {
    7779            Object.defineProperty( deprecatedObject, key, { get: function() {
    78                 deprecatedProperty( propName, '5.5.0', 'wp.i18n' );
     80                deprecatedProperty( propName, version, 'wp.i18n' );
    7981                return prop;
    8082            } } );
     
    100102};
    101103
    102 window.commonL10n = deprecateL10nObject( 'commonL10n', window.commonL10n );
     104window.commonL10n = deprecateL10nObject( 'commonL10n', window.commonL10n, '5.5.0' );
    103105
    104106/**
     
    112114};
    113115
    114 window.wpPointerL10n = deprecateL10nObject( 'wpPointerL10n', window.wpPointerL10n );
     116window.wpPointerL10n = deprecateL10nObject( 'wpPointerL10n', window.wpPointerL10n, '5.5.0' );
    115117
    116118/**
     
    130132};
    131133
    132 window.userProfileL10n = deprecateL10nObject( 'userProfileL10n', window.userProfileL10n );
     134window.userProfileL10n = deprecateL10nObject( 'userProfileL10n', window.userProfileL10n, '5.5.0' );
    133135
    134136/**
     
    149151};
    150152
    151 window.privacyToolsL10n = deprecateL10nObject( 'privacyToolsL10n', window.privacyToolsL10n );
     153window.privacyToolsL10n = deprecateL10nObject( 'privacyToolsL10n', window.privacyToolsL10n, '5.5.0' );
    152154
    153155/**
     
    161163};
    162164
    163 window.authcheckL10n = window.authcheckL10n || deprecateL10nObject( 'authcheckL10n', window.authcheckL10n );
     165window.authcheckL10n = window.authcheckL10n || deprecateL10nObject( 'authcheckL10n', window.authcheckL10n, '5.5.0' );
    164166
    165167/**
     
    174176};
    175177
    176 window.tagsl10n = window.tagsl10n || deprecateL10nObject( 'tagsl10n', window.tagsl10n );
     178window.tagsl10n = window.tagsl10n || deprecateL10nObject( 'tagsl10n', window.tagsl10n, '5.5.0' );
    177179
    178180/**
     
    199201};
    200202
    201 window.adminCommentsL10n = deprecateL10nObject( 'adminCommentsL10n', window.adminCommentsL10n );
     203window.adminCommentsL10n = deprecateL10nObject( 'adminCommentsL10n', window.adminCommentsL10n, '5.5.0' );
    202204
    203205/**
     
    215217};
    216218
    217 window.tagsSuggestL10n = deprecateL10nObject( 'tagsSuggestL10n', window.tagsSuggestL10n );
     219window.tagsSuggestL10n = deprecateL10nObject( 'tagsSuggestL10n', window.tagsSuggestL10n, '5.5.0' );
    218220
    219221/**
     
    232234};
    233235
    234 window.wpColorPickerL10n = deprecateL10nObject( 'wpColorPickerL10n', window.wpColorPickerL10n );
     236window.wpColorPickerL10n = deprecateL10nObject( 'wpColorPickerL10n', window.wpColorPickerL10n, '5.5.0' );
    235237
    236238/**
     
    244246};
    245247
    246 window.attachMediaBoxL10n = deprecateL10nObject( 'attachMediaBoxL10n', window.attachMediaBoxL10n );
     248window.attachMediaBoxL10n = deprecateL10nObject( 'attachMediaBoxL10n', window.attachMediaBoxL10n, '5.5.0' );
    247249
    248250/**
     
    277279};
    278280
    279 window.postL10n = deprecateL10nObject( 'postL10n', window.postL10n );
     281window.postL10n = deprecateL10nObject( 'postL10n', window.postL10n, '5.5.0' );
    280282
    281283/**
     
    293295};
    294296
    295 window.inlineEditL10n = deprecateL10nObject( 'inlineEditL10n', window.inlineEditL10n );
     297window.inlineEditL10n = deprecateL10nObject( 'inlineEditL10n', window.inlineEditL10n, '5.5.0' );
    296298
    297299/**
     
    307309};
    308310
    309 window.plugininstallL10n = deprecateL10nObject( 'plugininstallL10n', window.plugininstallL10n );
     311window.plugininstallL10n = deprecateL10nObject( 'plugininstallL10n', window.plugininstallL10n, '5.5.0' );
    310312
    311313/**
     
    322324};
    323325
    324 window.navMenuL10n = deprecateL10nObject( 'navMenuL10n', window.navMenuL10n );
     326window.navMenuL10n = deprecateL10nObject( 'navMenuL10n', window.navMenuL10n, '5.5.0' );
    325327
    326328/**
     
    335337};
    336338
    337 window.commentL10n = deprecateL10nObject( 'commentL10n', window.commentL10n );
     339window.commentL10n = deprecateL10nObject( 'commentL10n', window.commentL10n, '5.5.0' );
    338340
    339341/**
     
    350352};
    351353
    352 window.setPostThumbnailL10n = deprecateL10nObject( 'setPostThumbnailL10n', window.setPostThumbnailL10n );
     354window.setPostThumbnailL10n = deprecateL10nObject( 'setPostThumbnailL10n', window.setPostThumbnailL10n, '5.5.0' );
    353355
    354356/**
  • trunk/src/js/_enqueues/admin/widgets.js

    r48923 r49151  
    761761};
    762762
    763 wpWidgets.l10n = window.wp.deprecateL10nObject( 'wpWidgets.l10n', wpWidgets.l10n );
     763wpWidgets.l10n = window.wp.deprecateL10nObject( 'wpWidgets.l10n', wpWidgets.l10n, '5.5.0' );
  • trunk/src/js/_enqueues/wp/dashboard.js

    r49146 r49151  
    66/* global ajaxPopulateWidgets, quickPressLoad,  */
    77window.wp = window.wp || {};
     8window.communityEventsData = window.communityEventsData || {};
    89
    910/**
     
    266267    'use strict';
    267268
    268     var communityEventsData = window.communityEventsData || {},
     269    var communityEventsData = window.communityEventsData,
    269270        dateI18n = wp.date.dateI18n,
    270271        format = wp.date.format,
     
    467468            var template,
    468469                elementVisibility,
    469                 l10nPlaceholder  = /%(?:\d\$)?s/g, // Match `%s`, `%1$s`, `%2$s`, etc.
    470470                $toggleButton    = $( '.community-events-toggle-location' ),
    471471                $locationMessage = $( '#community-events-location-message' ),
     
    506506                 * provide events, but not a specific location.
    507507                 */
    508                 $locationMessage.text( communityEventsData.l10n.attend_event_near_generic );
     508                $locationMessage.text( __( 'Attend an upcoming event near you.' ) );
    509509
    510510                if ( templateParams.events.length ) {
     
    533533
    534534                if ( 'user' === initiatedBy ) {
    535                     wp.a11y.speak( communityEventsData.l10n.city_updated.replace( l10nPlaceholder, templateParams.location.description ), 'assertive' );
     535                    wp.a11y.speak(
     536                        sprintf(
     537                            /* translators: %s: The name of a city. */
     538                            __( 'City updated. Listing events near %s.' ),
     539                            templateParams.location.description
     540                        ),
     541                        'assertive'
     542                    );
    536543                }
    537544
     
    543550                template = wp.template( 'community-events-could-not-locate' );
    544551                $( '.community-events-could-not-locate' ).html( template( templateParams ) );
    545                 wp.a11y.speak( communityEventsData.l10n.could_not_locate_city.replace( l10nPlaceholder, templateParams.unknownCity ) );
     552                wp.a11y.speak(
     553                    sprintf(
     554                        /*
     555                         * These specific examples were chosen to highlight the fact that a
     556                         * state is not needed, even for cities whose name is not unique.
     557                         * It would be too cumbersome to include that in the instructions
     558                         * to the user, so it's left as an implication.
     559                         */
     560                        /*
     561                         * translators: %s is the name of the city we couldn't locate.
     562                         * Replace the examples with cities related to your locale. Test that
     563                         * they match the expected location and have upcoming events before
     564                         * including them. If no cities related to your locale have events,
     565                         * then use cities related to your locale that would be recognizable
     566                         * to most users. Use only the city name itself, without any region
     567                         * or country. Use the endonym (native locale name) instead of the
     568                         * English name if possible.
     569                         */
     570                        __( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
     571                        templateParams.unknownCity
     572                    )
     573                );
    546574
    547575                elementVisibility['.community-events-errors']           = true;
     
    555583                 * could be confusing or unnecessarily distracting.
    556584                 */
    557                 wp.a11y.speak( communityEventsData.l10n.error_occurred_please_try_again );
     585                wp.a11y.speak( __( 'An error occurred. Please try again.' ) );
    558586
    559587                elementVisibility['.community-events-errors']         = true;
    560588                elementVisibility['.community-events-error-occurred'] = true;
    561589            } else {
    562                 $locationMessage.text( communityEventsData.l10n.enter_closest_city );
     590                $locationMessage.text( __( 'Enter your closest city to find nearby events.' ) );
    563591
    564592                elementVisibility['#community-events-location-message'] = true;
     
    792820    }
    793821});
     822
     823/**
     824 * Removed in 5.6.0, needed for back-compatibility.
     825 *
     826 * @since 4.8.0
     827 * @deprecated 5.6.0
     828 *
     829 * @type {object}
     830*/
     831window.communityEventsData.l10n = window.communityEventsData.l10n || {
     832    enter_closest_city: '',
     833    error_occurred_please_try_again: '',
     834    attend_event_near_generic: '',
     835    could_not_locate_city: '',
     836    city_updated: ''
     837};
     838
     839window.communityEventsData.l10n = window.wp.deprecateL10nObject( 'communityEventsData.l10n', window.communityEventsData.l10n, '5.6.0' );
  • trunk/src/js/_enqueues/wp/theme-plugin-editor.js

    r48923 r49151  
    10241024};
    10251025
    1026 wp.themePluginEditor.l10n = window.wp.deprecateL10nObject( 'wp.themePluginEditor.l10n', wp.themePluginEditor.l10n );
     1026wp.themePluginEditor.l10n = window.wp.deprecateL10nObject( 'wp.themePluginEditor.l10n', wp.themePluginEditor.l10n, '5.5.0' );
  • trunk/src/js/_enqueues/wp/updates.js

    r48923 r49151  
    116116    };
    117117
    118     wp.updates.l10n = window.wp.deprecateL10nObject( 'wp.updates.l10n', wp.updates.l10n );
     118    wp.updates.l10n = window.wp.deprecateL10nObject( 'wp.updates.l10n', wp.updates.l10n, '5.5.0' );
    119119
    120120    /**
  • trunk/src/wp-includes/script-loader.php

    r49147 r49151  
    17581758            'cache'       => $events_client->get_cached_events(),
    17591759            'time_format' => get_option( 'time_format' ),
    1760 
    1761             'l10n'        => array(
    1762                 'enter_closest_city'              => __( 'Enter your closest city to find nearby events.' ),
    1763                 'error_occurred_please_try_again' => __( 'An error occurred. Please try again.' ),
    1764                 'attend_event_near_generic'       => __( 'Attend an upcoming event near you.' ),
    1765 
    1766                 /*
    1767                  * These specific examples were chosen to highlight the fact that a
    1768                  * state is not needed, even for cities whose name is not unique.
    1769                  * It would be too cumbersome to include that in the instructions
    1770                  * to the user, so it's left as an implication.
    1771                  */
    1772                 /*
    1773                  * translators: %s is the name of the city we couldn't locate.
    1774                  * Replace the examples with cities related to your locale. Test that
    1775                  * they match the expected location and have upcoming events before
    1776                  * including them. If no cities related to your locale have events,
    1777                  * then use cities related to your locale that would be recognizable
    1778                  * to most users. Use only the city name itself, without any region
    1779                  * or country. Use the endonym (native locale name) instead of the
    1780                  * English name if possible.
    1781                  */
    1782                 'could_not_locate_city'           => __( 'We couldn’t locate %s. Please try another nearby city. For example: Kansas City; Springfield; Portland.' ),
    1783 
    1784                 // This one is only used with wp.a11y.speak(), so it can/should be more brief.
    1785                 /* translators: %s: The name of a city. */
    1786                 'city_updated'                    => __( 'City updated. Listing events near %s.' ),
    1787             ),
    17881760        )
    17891761    );
  • trunk/tests/qunit/index.html

    r49146 r49151  
    8383            <script src="fixtures/js-widgets-endpoint.js"></script>
    8484            <script src="fixtures/wp-api.js"></script>
     85            <script src="fixtures/common.js"></script>
    8586        </div>
    8687
Note: See TracChangeset for help on using the changeset viewer.