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
This commit is contained in:
Pascal Birchler
2016-10-03 07:03:41 +00:00
parent d3afcc4e33
commit f231e7233d
20 changed files with 170 additions and 24 deletions

View File

@@ -75,6 +75,23 @@ function get_locale() {
return apply_filters( 'locale', $locale );
}
/**
* Retrieves the locale of the current user.
*
* If the user has a locale set to a non-empty string then it will be
* returned. Otherwise it returns the locale of get_locale().
*
* @since 4.7.0
*
* @return string The locale of the current user.
*/
function get_user_locale() {
$user = wp_get_current_user();
$locale = $user->locale;
return ( '' === $locale ) ? get_locale() : $locale;
}
/**
* Retrieve the translation of $text.
*
@@ -633,7 +650,7 @@ function unload_textdomain( $domain ) {
*/
function load_default_textdomain( $locale = null ) {
if ( null === $locale ) {
$locale = get_locale();
$locale = is_admin() ? get_user_locale() : get_locale();
}
// Unload previously loaded strings so we can switch translations.
@@ -1148,4 +1165,4 @@ function is_rtl() {
return false;
}
return $wp_locale->is_rtl();
}
}