Skip to content

Commit f231e72

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@38705 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d3afcc4 commit f231e72

20 files changed

Lines changed: 170 additions & 24 deletions

src/wp-admin/admin-header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
$admin_body_class .= ' branch-' . str_replace( array( '.', ',' ), '-', floatval( get_bloginfo( 'version' ) ) );
157157
$admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', get_bloginfo( 'version' ) ) );
158158
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
159-
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
159+
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
160160

161161
if ( wp_is_mobile() )
162162
$admin_body_class .= ' mobile';

src/wp-admin/includes/class-wp-plugin-install-list-table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function prepare_items() {
134134
'active_installs' => true
135135
),
136136
// Send the locale and installed plugin slugs to the API so it can provide context-sensitive results.
137-
'locale' => get_locale(),
137+
'locale' => get_user_locale(),
138138
'installed_plugins' => $this->get_installed_plugin_slugs(),
139139
);
140140

src/wp-admin/includes/class-wp-press-this.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ public function html() {
13121312
$admin_body_class .= ' branch-' . str_replace( array( '.', ',' ), '-', floatval( $wp_version ) );
13131313
$admin_body_class .= ' version-' . str_replace( '.', '-', preg_replace( '/^([.0-9]+).*/', '$1', $wp_version ) );
13141314
$admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' );
1315-
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
1315+
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
13161316

13171317
/** This filter is documented in wp-admin/admin-header.php */
13181318
$admin_body_classes = apply_filters( 'admin_body_class', '' );

src/wp-admin/includes/credits.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
function wp_credits() {
1818
$wp_version = get_bloginfo( 'version' );
19-
$locale = get_locale();
19+
$locale = get_user_locale();
2020

2121
$results = get_site_transient( 'wordpress_credits_' . $locale );
2222

src/wp-admin/includes/dashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,7 @@ function wp_dashboard_browser_nag() {
13531353
$notice .= "<p class='browser-update-nag{$browser_nag_class}'>{$msg}</p>";
13541354

13551355
$browsehappy = 'http://browsehappy.com/';
1356-
$locale = get_locale();
1356+
$locale = get_user_locale();
13571357
if ( 'en_US' !== $locale )
13581358
$browsehappy = add_query_arg( 'locale', $locale, $browsehappy );
13591359

src/wp-admin/includes/import.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ function wp_import_handle_upload() {
125125
function wp_get_popular_importers() {
126126
include( ABSPATH . WPINC . '/version.php' ); // include an unmodified $wp_version
127127

128-
$locale = get_locale();
128+
$locale = get_user_locale();
129129
$cache_key = 'popular_importers_' . md5( $locale . $wp_version );
130130
$popular_importers = get_site_transient( $cache_key );
131131

132132
if ( ! $popular_importers ) {
133133
$url = add_query_arg( array(
134-
'locale' => get_locale(),
134+
'locale' => get_user_locale(),
135135
'version' => $wp_version,
136136
), 'http://api.wordpress.org/core/importers/1.1/' );
137137
$options = array( 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url() );

src/wp-admin/includes/plugin-install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function plugins_api( $action, $args = array() ) {
109109
}
110110

111111
if ( ! isset( $args->locale ) ) {
112-
$args->locale = get_locale();
112+
$args->locale = get_user_locale();
113113
}
114114

115115
/**

src/wp-admin/includes/template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ function tb_close(){var win=window.dialogArguments||opener||parent||top;win.tb_r
16221622
/** This action is documented in wp-admin/admin-header.php */
16231623
do_action( 'admin_head' );
16241624

1625-
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
1625+
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
16261626

16271627
if ( is_rtl() )
16281628
$admin_body_class .= ' rtl';

src/wp-admin/includes/theme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ function themes_api( $action, $args = array() ) {
412412
}
413413

414414
if ( ! isset( $args->locale ) ) {
415-
$args->locale = get_locale();
415+
$args->locale = get_user_locale();
416416
}
417417

418418
/**

src/wp-admin/includes/user.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ function edit_user( $user_id = 0 ) {
9494
$user->rich_editing = isset( $_POST['rich_editing'] ) && 'false' == $_POST['rich_editing'] ? 'false' : 'true';
9595
$user->admin_color = isset( $_POST['admin_color'] ) ? sanitize_text_field( $_POST['admin_color'] ) : 'fresh';
9696
$user->show_admin_bar_front = isset( $_POST['admin_bar_front'] ) ? 'true' : 'false';
97+
$user->locale = '';
98+
99+
if ( isset( $_POST['locale'] ) ) {
100+
$locale = sanitize_text_field( $_POST['locale'] );
101+
if ( ! in_array( $locale, get_available_languages(), true ) ) {
102+
$locale = '';
103+
}
104+
105+
$user->locale = ( '' === $locale ) ? 'en_US' : $locale;
106+
}
97107
}
98108

99109
$user->comment_shortcuts = isset( $_POST['comment_shortcuts'] ) && 'true' == $_POST['comment_shortcuts'] ? 'true' : '';

0 commit comments

Comments
 (0)