Make WordPress Core


Ignore:
Timestamp:
11/08/2021 10:36:11 PM (2 years ago)
Author:
joedolson
Message:

I18N: Add language switcher on login/registration screens.

Load a language switcher on the login and registration screens that allows users to choose any already-installed language. Set user locale on registration.

Props johnbillion, Nikschavan, afercia, sabernhardt, garrett-eclipse, keyur5, paaljoachim, Clorith, tobifjellner.
Fixes #43700.

File:
1 edited

Legend:

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

    r51837 r52058  
    145145    }
    146146
    147     if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
    148         $determined_locale = sanitize_text_field( $_GET['wp_lang'] );
     147    $wp_lang = '';
     148
     149    if ( ! empty( $_GET['wp_lang'] ) ) {
     150        $wp_lang = sanitize_text_field( $_GET['wp_lang'] );
     151    } elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
     152        $wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] );
     153    }
     154
     155    if ( ! empty( $wp_lang ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
     156        $determined_locale = $wp_lang;
    149157    }
    150158
     
    14811489 * @since 4.7.0 Introduced the `show_option_site_default` argument.
    14821490 * @since 5.1.0 Introduced the `show_option_en_us` argument.
     1491 * @since 5.9.0 Introduced the `explicit_option_en_us` argument.
    14831492 *
    14841493 * @see get_available_languages()
     
    15001509 *     @type bool     $show_option_site_default     Whether to show an option to fall back to the site's locale. Default false.
    15011510 *     @type bool     $show_option_en_us            Whether to show an option for English (United States). Default true.
     1511 *     @type bool     $explicit_option_en_us        Whether the English (United States) option uses an explict value of en_US
     1512 *                                                  instead of an empty value. Default false.
    15021513 * }
    15031514 * @return string HTML dropdown list of languages.
     
    15171528            'show_option_site_default'    => false,
    15181529            'show_option_en_us'           => true,
     1530            'explicit_option_en_us'       => false,
    15191531        )
    15201532    );
     
    15261538
    15271539    // English (United States) uses an empty string for the value attribute.
    1528     if ( 'en_US' === $parsed_args['selected'] ) {
     1540    if ( 'en_US' === $parsed_args['selected'] && ! $parsed_args['explicit_option_en_us'] ) {
    15291541        $parsed_args['selected'] = '';
    15301542    }
     
    15811593
    15821594    if ( $parsed_args['show_option_en_us'] ) {
     1595        $value = ( $parsed_args['explicit_option_en_us'] ) ? 'en_US' : '';
    15831596        $structure[] = sprintf(
    1584             '<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
     1597            '<option value="%s" lang="en" data-installed="1"%s>English (United States)</option>',
     1598            esc_attr( $value ),
    15851599            selected( '', $parsed_args['selected'], false )
    15861600        );
Note: See TracChangeset for help on using the changeset viewer.