Make WordPress Core

Ticket #54561: 54561.patch

File 54561.patch, 4.5 KB (added by Chouby, 3 years ago)

Avoid 27 duplicate translations

  • src/wp-includes/widgets/class-wp-widget-media.php

    diff --git src/wp-includes/widgets/class-wp-widget-media.php src/wp-includes/widgets/class-wp-widget-media.php
    index cd633e2908..b394e377c3 100644
    abstract class WP_Widget_Media extends WP_Widget { 
    4141         */
    4242        protected $registered = false;
    4343
     44        /**
     45         * The default widget description.
     46         *
     47         * @since 6.0
     48         * @var string
     49         */
     50        protected static $default_description;
     51
     52        /**
     53         * The default localized strings used by the widget.
     54         *
     55         * @since 6.0
     56         * @var string[]
     57         */
     58        protected static $l10n_defaults;
     59
    4460        /**
    4561         * Constructor.
    4662         *
    abstract class WP_Widget_Media extends WP_Widget { 
    5773                $widget_opts = wp_parse_args(
    5874                        $widget_options,
    5975                        array(
    60                                 'description'                 => __( 'A media item.' ),
     76                                'description'                 => self::get_default_description(),
    6177                                'customize_selective_refresh' => true,
    6278                                'show_instance_in_rest'       => true,
    6379                                'mime_type'                   => '',
    abstract class WP_Widget_Media extends WP_Widget { 
    6682
    6783                $control_opts = wp_parse_args( $control_options, array() );
    6884
    69                 $l10n_defaults = array(
    70                         'no_media_selected'          => __( 'No media selected' ),
    71                         'add_media'                  => _x( 'Add Media', 'label for button in the media widget' ),
    72                         'replace_media'              => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
    73                         'edit_media'                 => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
    74                         'add_to_widget'              => __( 'Add to Widget' ),
    75                         'missing_attachment'         => sprintf(
    76                                 /* translators: %s: URL to media library. */
    77                                 __( 'We can&#8217;t find that file. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
    78                                 esc_url( admin_url( 'upload.php' ) )
    79                         ),
    80                         /* translators: %d: Widget count. */
    81                         'media_library_state_multi'  => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
    82                         'media_library_state_single' => __( 'Media Widget' ),
    83                         'unsupported_file_type'      => __( 'Looks like this isn&#8217;t the correct kind of file. Please link to an appropriate file instead.' ),
    84                 );
    85                 $this->l10n    = array_merge( $l10n_defaults, array_filter( $this->l10n ) );
     85                $this->l10n    = array_merge( self::get_l10n_defaults(), array_filter( $this->l10n ) );
    8686
    8787                parent::__construct(
    8888                        $id_base,
    abstract class WP_Widget_Media extends WP_Widget { 
    451451        protected function has_content( $instance ) {
    452452                return ( $instance['attachment_id'] && 'attachment' === get_post_type( $instance['attachment_id'] ) ) || $instance['url'];
    453453        }
     454
     455        /**
     456         * Returns the default description of the widget.
     457         *
     458         * @since 6.0
     459         *
     460         * @var string
     461         */
     462        protected static function get_default_description() {
     463                if ( self::$default_description ) {
     464                        return self::$default_description;
     465                }
     466
     467                self::$default_description = __( 'A media item.' );
     468                return self::$default_description;
     469        }
     470
     471        /**
     472         * Returns the default localized strings used by the widget.
     473         *
     474         * @since 6.0
     475         *
     476         * @return string[]
     477         */
     478        protected static function get_l10n_defaults() {
     479                if ( self::$l10n_defaults ) {
     480                        return self::$l10n_defaults;
     481                }
     482
     483                self::$l10n_defaults = array(
     484                        'no_media_selected'          => __( 'No media selected' ),
     485                        'add_media'                  => _x( 'Add Media', 'label for button in the media widget' ),
     486                        'replace_media'              => _x( 'Replace Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
     487                        'edit_media'                 => _x( 'Edit Media', 'label for button in the media widget; should preferably not be longer than ~13 characters long' ),
     488                        'add_to_widget'              => __( 'Add to Widget' ),
     489                        'missing_attachment'         => sprintf(
     490                                /* translators: %s: URL to media library. */
     491                                __( 'We can&#8217;t find that file. Check your <a href="%s">media library</a> and make sure it wasn&#8217;t deleted.' ),
     492                                esc_url( admin_url( 'upload.php' ) )
     493                        ),
     494                        /* translators: %d: Widget count. */
     495                        'media_library_state_multi'  => _n_noop( 'Media Widget (%d)', 'Media Widget (%d)' ),
     496                        'media_library_state_single' => __( 'Media Widget' ),
     497                        'unsupported_file_type'      => __( 'Looks like this isn&#8217;t the correct kind of file. Please link to an appropriate file instead.' ),
     498                );
     499
     500                return self::$l10n_defaults;
     501        }
    454502}