WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/03/2016 07:03:41 AM (4 years ago)
Author:
swissspidy
Message:

I18N: Introduce a user-specific language setting.

By enabling the user to select their preferred locale when editing the profile, we allow for greater personalization of the WordPress admin and therefore a better user experience.

The back end will be displayed in the user's individual locale while the locale used on the front end equals the one set for the whole site. If the user didn't specify a locale, the site's locale will be used as a fallback. The new locale property of the WP_User class can be used to retrieve the user's locale setting.

Props ocean90, ipm-frommen, swissspidy.
Fixes #29783.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/user-edit.php

    r38672 r38705  
    270270</td>
    271271</tr>
     272
     273<?php
     274$languages = get_available_languages();
     275if ( $languages ) : ?>
     276<tr class="user-language-wrap">
     277    <th scope="row">
     278        <label for="site_language"><?php _e( 'Site Language' ); ?></label>
     279    </th>
     280    <td>
     281        <?php
     282        $user_locale = get_user_option( 'locale', $profileuser->ID );
     283
     284        if ( 'en_US' === $user_locale ) { // en_US
     285            $user_locale = false;
     286        } elseif ( ! in_array( $user_locale, $languages, true ) ) {
     287            $user_locale = get_locale();
     288        }
     289
     290        wp_dropdown_languages( array(
     291            'name'                        => 'locale',
     292            'id'                          => 'locale',
     293            'selected'                    => $user_locale,
     294            'languages'                   => $languages,
     295            'show_available_translations' => false
     296        ) );
     297        ?>
     298    </td>
     299</tr>
     300<?php
     301endif;
     302?>
     303
    272304<?php
    273305/**
Note: See TracChangeset for help on using the changeset viewer.