Make WordPress Core

Changeset 44514


Ignore:
Timestamp:
01/09/2019 11:45:02 AM (6 years ago)
Author:
swissspidy
Message:

I18N: Add option to hide en_US locale in wp_dropdown_languages().

Props danieltj for initial patch.
Fixes #44494.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r44418 r44514  
    13651365 * @since 4.3.0 Introduced the `echo` argument.
    13661366 * @since 4.7.0 Introduced the `show_option_site_default` argument.
     1367 * @since 5.1.0 Introduced the `show_option_en_us` argument.
    13671368 *
    13681369 * @see get_available_languages()
     
    13831384 *     @type bool     $show_available_translations  Whether to show available translations. Default true.
    13841385 *     @type bool     $show_option_site_default     Whether to show an option to fall back to the site's locale. Default false.
     1386 *     @type bool     $show_option_en_us            Whether to show an option for English (United States). Default true.
    13851387 * }
    13861388 * @return string HTML content
     
    13991401            'show_available_translations' => true,
    14001402            'show_option_site_default'    => false,
     1403            'show_option_en_us'           => true,
    14011404        )
    14021405    );
     
    14621465    }
    14631466
    1464     // Always show English.
    1465     $structure[] = sprintf(
    1466         '<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
    1467         selected( '', $parsed_args['selected'], false )
    1468     );
     1467    if ( $parsed_args['show_option_en_us'] ) {
     1468        $structure[] = sprintf(
     1469            '<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
     1470            selected( '', $parsed_args['selected'], false )
     1471        );
     1472    }
    14691473
    14701474    // List installed languages.
  • trunk/tests/phpunit/tests/l10n.php

    r43359 r44514  
    123123        $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual );
    124124        $this->assertContains( '<option value="ja_JP" lang="ja">日本語</option>', $actual );
     125    }
     126
     127    /**
     128     * @ticket 44494
     129     */
     130    function test_wp_dropdown_languages_exclude_en_us() {
     131        $args   = array(
     132            'id'                       => 'foo',
     133            'name'                     => 'bar',
     134            'languages'                => array( 'de_DE' ),
     135            'translations'             => $this->wp_dropdown_languages_filter(),
     136            'selected'                 => 'de_DE',
     137            'echo'                     => false,
     138            'show_option_en_us'        => false,
     139        );
     140        $actual = wp_dropdown_languages( $args );
     141
     142        $this->assertNotContains( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
    125143    }
    126144
Note: See TracChangeset for help on using the changeset viewer.