Make WordPress Core


Ignore:
Timestamp:
11/08/2016 11:00:38 PM (10 years ago)
Author:
swissspidy
Message:

I18N: Add ability to change user's locale back to site's locale.

Previously there was no way to remove the user locale setting again, even though that might be desirable.

This adds a new 'Site Default' option to the user-specific language setting by introducing a new show_site_locale_default argument to wp_dropdown_languages().

Props ocean90.
See #29783.
Fixes #38632.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/l10n.php

    r39125 r39169  
    101101
    102102    /**
     103     * @ticket 38632
     104     */
     105    function test_wp_dropdown_languages_site_default() {
     106        $args = array(
     107            'id'                       => 'foo',
     108            'name'                     => 'bar',
     109            'languages'                => array( 'de_DE' ),
     110            'translations'             => $this->wp_dropdown_languages_filter(),
     111            'selected'                 => 'de_DE',
     112            'echo'                     => false,
     113            'show_site_locale_default' => true,
     114        );
     115        $actual = wp_dropdown_languages( $args );
     116
     117        $this->assertContains( 'id="foo"', $actual );
     118        $this->assertContains( 'name="bar"', $actual );
     119        $this->assertContains( '<option value="site-default" data-installed="1">Site Default</option>', $actual );
     120        $this->assertContains( '<option value="" lang="en" data-installed="1">English (United States)</option>', $actual );
     121        $this->assertContains( '<option value="de_DE" lang="de" selected=\'selected\' data-installed="1">Deutsch</option>', $actual );
     122        $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual );
     123    }
     124
     125    /**
     126     * @ticket 38632
     127     */
     128    function test_wp_dropdown_languages_en_US_selected() {
     129        $args = array(
     130            'id'           => 'foo',
     131            'name'         => 'bar',
     132            'languages'    => array( 'de_DE' ),
     133            'translations' => $this->wp_dropdown_languages_filter(),
     134            'selected'     => 'en_US',
     135            'echo'         => false,
     136        );
     137        $actual = wp_dropdown_languages( $args );
     138
     139        $this->assertContains( 'id="foo"', $actual );
     140        $this->assertContains( 'name="bar"', $actual );
     141        $this->assertContains( '<option value="" lang="en" data-installed="1" selected=\'selected\'>English (United States)</option>', $actual );
     142        $this->assertContains( '<option value="de_DE" lang="de" data-installed="1">Deutsch</option>', $actual );
     143        $this->assertContains( '<option value="it_IT" lang="it">Italiano</option>', $actual );
     144    }
     145
     146    /**
    103147     * We don't want to call the API when testing.
    104148     *
Note: See TracChangeset for help on using the changeset viewer.