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. Built from https://develop.svn.wordpress.org/trunk@52058 git-svn-id: http://core.svn.wordpress.org/trunk@51650 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8e7b8a1837
commit
d00b86ff06
|
@ -282,7 +282,7 @@ p {
|
|||
|
||||
#login {
|
||||
width: 320px;
|
||||
padding: 8% 0 0;
|
||||
padding: 5% 0 0;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
|
@ -322,7 +322,7 @@ p {
|
|||
.login .privacy-policy-page-link {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
margin: 5em 0 2em;
|
||||
margin: 3em 0 2em;
|
||||
}
|
||||
|
||||
.login form .input,
|
||||
|
@ -410,10 +410,46 @@ input::-ms-reveal {
|
|||
display: none;
|
||||
}
|
||||
|
||||
#language-switcher {
|
||||
padding: 0;
|
||||
overflow: visible;
|
||||
background: none;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
#language-switcher select {
|
||||
margin-left: 0.25em;
|
||||
}
|
||||
|
||||
.language-switcher {
|
||||
margin: 0 auto;
|
||||
padding: 0 0 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.language-switcher label {
|
||||
margin-left: 0.25em;
|
||||
}
|
||||
|
||||
.language-switcher label .dashicons {
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.login .language-switcher .button-primary {
|
||||
float: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@media screen and (max-height: 550px) {
|
||||
#login {
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
#language-switcher {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -428,4 +464,16 @@ input::-ms-reveal {
|
|||
height: 1.3125rem;
|
||||
margin: -0.1875rem -0.25rem 0 0;
|
||||
}
|
||||
|
||||
#language-switcher label,
|
||||
#language-switcher select {
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 400px) {
|
||||
.login .language-switcher .button-primary {
|
||||
display: block;
|
||||
margin: 5px auto 0;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -281,7 +281,7 @@ p {
|
|||
|
||||
#login {
|
||||
width: 320px;
|
||||
padding: 8% 0 0;
|
||||
padding: 5% 0 0;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
|
@ -321,7 +321,7 @@ p {
|
|||
.login .privacy-policy-page-link {
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
margin: 5em 0 2em;
|
||||
margin: 3em 0 2em;
|
||||
}
|
||||
|
||||
.login form .input,
|
||||
|
@ -409,10 +409,46 @@ input::-ms-reveal {
|
|||
display: none;
|
||||
}
|
||||
|
||||
#language-switcher {
|
||||
padding: 0;
|
||||
overflow: visible;
|
||||
background: none;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
#language-switcher select {
|
||||
margin-right: 0.25em;
|
||||
}
|
||||
|
||||
.language-switcher {
|
||||
margin: 0 auto;
|
||||
padding: 0 0 24px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.language-switcher label {
|
||||
margin-right: 0.25em;
|
||||
}
|
||||
|
||||
.language-switcher label .dashicons {
|
||||
width: auto;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.login .language-switcher .button-primary {
|
||||
float: none;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@media screen and (max-height: 550px) {
|
||||
#login {
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
#language-switcher {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -427,4 +463,16 @@ input::-ms-reveal {
|
|||
height: 1.3125rem;
|
||||
margin: -0.1875rem 0 0 -0.25rem;
|
||||
}
|
||||
|
||||
#language-switcher label,
|
||||
#language-switcher select {
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 400px) {
|
||||
.login .language-switcher .button-primary {
|
||||
display: block;
|
||||
margin: 5px auto 0;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -144,8 +144,16 @@ function determine_locale() {
|
|||
$determined_locale = get_user_locale();
|
||||
}
|
||||
|
||||
if ( ! empty( $_GET['wp_lang'] ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
|
||||
$determined_locale = sanitize_text_field( $_GET['wp_lang'] );
|
||||
$wp_lang = '';
|
||||
|
||||
if ( ! empty( $_GET['wp_lang'] ) ) {
|
||||
$wp_lang = sanitize_text_field( $_GET['wp_lang'] );
|
||||
} elseif ( ! empty( $_COOKIE['wp_lang'] ) ) {
|
||||
$wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $wp_lang ) && ! empty( $GLOBALS['pagenow'] ) && 'wp-login.php' === $GLOBALS['pagenow'] ) {
|
||||
$determined_locale = $wp_lang;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1480,6 +1488,7 @@ function wp_get_pomo_file_data( $po_file ) {
|
|||
* @since 4.3.0 Introduced the `echo` argument.
|
||||
* @since 4.7.0 Introduced the `show_option_site_default` argument.
|
||||
* @since 5.1.0 Introduced the `show_option_en_us` argument.
|
||||
* @since 5.9.0 Introduced the `explicit_option_en_us` argument.
|
||||
*
|
||||
* @see get_available_languages()
|
||||
* @see wp_get_available_translations()
|
||||
|
@ -1499,6 +1508,8 @@ function wp_get_pomo_file_data( $po_file ) {
|
|||
* @type bool $show_available_translations Whether to show available translations. Default true.
|
||||
* @type bool $show_option_site_default Whether to show an option to fall back to the site's locale. Default false.
|
||||
* @type bool $show_option_en_us Whether to show an option for English (United States). Default true.
|
||||
* @type bool $explicit_option_en_us Whether the English (United States) option uses an explict value of en_US
|
||||
* instead of an empty value. Default false.
|
||||
* }
|
||||
* @return string HTML dropdown list of languages.
|
||||
*/
|
||||
|
@ -1516,6 +1527,7 @@ function wp_dropdown_languages( $args = array() ) {
|
|||
'show_available_translations' => true,
|
||||
'show_option_site_default' => false,
|
||||
'show_option_en_us' => true,
|
||||
'explicit_option_en_us' => false,
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1525,7 +1537,7 @@ function wp_dropdown_languages( $args = array() ) {
|
|||
}
|
||||
|
||||
// English (United States) uses an empty string for the value attribute.
|
||||
if ( 'en_US' === $parsed_args['selected'] ) {
|
||||
if ( 'en_US' === $parsed_args['selected'] && ! $parsed_args['explicit_option_en_us'] ) {
|
||||
$parsed_args['selected'] = '';
|
||||
}
|
||||
|
||||
|
@ -1580,8 +1592,10 @@ function wp_dropdown_languages( $args = array() ) {
|
|||
}
|
||||
|
||||
if ( $parsed_args['show_option_en_us'] ) {
|
||||
$value = ( $parsed_args['explicit_option_en_us'] ) ? 'en_US' : '';
|
||||
$structure[] = sprintf(
|
||||
'<option value="" lang="en" data-installed="1"%s>English (United States)</option>',
|
||||
'<option value="%s" lang="en" data-installed="1"%s>English (United States)</option>',
|
||||
esc_attr( $value ),
|
||||
selected( '', $parsed_args['selected'], false )
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3044,6 +3044,13 @@ function register_new_user( $user_login, $user_email ) {
|
|||
|
||||
update_user_meta( $user_id, 'default_password_nag', true ); // Set up the password change nag.
|
||||
|
||||
if ( ! empty( $_COOKIE['wp_lang'] ) ) {
|
||||
$wp_lang = sanitize_text_field( $_COOKIE['wp_lang'] );
|
||||
if ( in_array( $wp_lang, get_available_languages(), true ) ) {
|
||||
update_user_meta( $user_id, 'locale', $wp_lang ); // Set user locale if defined on registration.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires after a new user registration has been recorded.
|
||||
*
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.9-alpha-52057';
|
||||
$wp_version = '5.9-alpha-52058';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
56
wp-login.php
56
wp-login.php
|
@ -311,6 +311,58 @@ function login_footer( $input_id = '' ) {
|
|||
?>
|
||||
</div><?php // End of <div id="login">. ?>
|
||||
|
||||
<?php
|
||||
$languages = get_available_languages();
|
||||
|
||||
if ( ! empty( $languages ) && ! $interim_login ) { ?>
|
||||
|
||||
<div class="language-switcher">
|
||||
<form id="language-switcher" action="" method="get">
|
||||
|
||||
<label for="language-switcher-locales">
|
||||
<span class="dashicons dashicons-translation" aria-hidden="true"></span>
|
||||
<span class="screen-reader-text"><?php _e( 'Language' ); ?></span>
|
||||
</label>
|
||||
|
||||
<?php
|
||||
$args = array(
|
||||
'id' => 'language-switcher-locales',
|
||||
'name' => 'wp_lang',
|
||||
'selected' => determine_locale(),
|
||||
'show_available_translations' => false,
|
||||
'explicit_option_en_us' => true,
|
||||
'languages' => $languages,
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters default arguments for the Languages select input on the login screen.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @param array $args Arguments for the Languages select input on the login screen.
|
||||
*/
|
||||
wp_dropdown_languages( apply_filters( 'wp_login_language_switcher_args', $args ) );
|
||||
?>
|
||||
|
||||
<?php if ( $interim_login ) { ?>
|
||||
<input type="hidden" name="interim-login" value="1" />
|
||||
<?php } ?>
|
||||
|
||||
<?php if ( isset( $_GET['redirect_to'] ) && '' !== $_GET['redirect_to'] ) { ?>
|
||||
<input type="hidden" name="redirect_to" value="<?php echo esc_url_raw( $_GET['redirect_to'] ); ?>" />
|
||||
<?php } ?>
|
||||
|
||||
<?php if ( isset( $_GET['action'] ) && '' !== $_GET['action'] ) { ?>
|
||||
<input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action'] ); ?>" />
|
||||
<?php } ?>
|
||||
|
||||
<input type="submit" class="button button-primary" value="<?php esc_attr_e( 'Change' ); ?>">
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
|
||||
if ( ! empty( $input_id ) ) {
|
||||
|
@ -419,6 +471,10 @@ if ( SITECOOKIEPATH !== COOKIEPATH ) {
|
|||
setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
|
||||
}
|
||||
|
||||
if ( isset( $_GET['wp_lang'] ) ) {
|
||||
setcookie( 'wp_lang', sanitize_text_field( $_GET['wp_lang'] ), 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires when the login form is initialized.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue