I18N: Use the user's locale when loading text domains in the admin.
Leverages `get_user_locale()` in `load_*_textdomain()` and `_load_textdomain_just_in_time()` to always load translations in the user's language when in the admin. This re-introduces [39069], but now with additional tests and a `function_exists( 'wp_get_current_user' )` check in `get_user_locale()` in case it gets used early. Props swissspidy, ocean90. Fixes #38485. Built from https://develop.svn.wordpress.org/trunk@39127 git-svn-id: http://core.svn.wordpress.org/trunk@39067 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5564716a07
commit
b1ee6c64d9
|
@ -88,7 +88,7 @@ function get_locale() {
|
||||||
*/
|
*/
|
||||||
function get_user_locale( $user_id = 0 ) {
|
function get_user_locale( $user_id = 0 ) {
|
||||||
$user = false;
|
$user = false;
|
||||||
if ( 0 === $user_id ) {
|
if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
|
||||||
$user = wp_get_current_user();
|
$user = wp_get_current_user();
|
||||||
} elseif ( $user_id instanceof WP_User ) {
|
} elseif ( $user_id instanceof WP_User ) {
|
||||||
$user = $user_id;
|
$user = $user_id;
|
||||||
|
@ -710,7 +710,7 @@ function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path
|
||||||
* @param string $locale The plugin's current locale.
|
* @param string $locale The plugin's current locale.
|
||||||
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
||||||
*/
|
*/
|
||||||
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
|
$locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
|
||||||
|
|
||||||
$mofile = $domain . '-' . $locale . '.mo';
|
$mofile = $domain . '-' . $locale . '.mo';
|
||||||
|
|
||||||
|
@ -744,7 +744,7 @@ function load_plugin_textdomain( $domain, $deprecated = false, $plugin_rel_path
|
||||||
*/
|
*/
|
||||||
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
|
function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
|
||||||
/** This filter is documented in wp-includes/l10n.php */
|
/** This filter is documented in wp-includes/l10n.php */
|
||||||
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );
|
$locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
|
||||||
|
|
||||||
$mofile = $domain . '-' . $locale . '.mo';
|
$mofile = $domain . '-' . $locale . '.mo';
|
||||||
|
|
||||||
|
@ -783,7 +783,7 @@ function load_theme_textdomain( $domain, $path = false ) {
|
||||||
* @param string $locale The theme's current locale.
|
* @param string $locale The theme's current locale.
|
||||||
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
* @param string $domain Text domain. Unique identifier for retrieving translated strings.
|
||||||
*/
|
*/
|
||||||
$locale = apply_filters( 'theme_locale', get_locale(), $domain );
|
$locale = apply_filters( 'theme_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
|
||||||
|
|
||||||
$mofile = $domain . '-' . $locale . '.mo';
|
$mofile = $domain . '-' . $locale . '.mo';
|
||||||
|
|
||||||
|
@ -865,7 +865,7 @@ function _load_textdomain_just_in_time( $domain ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$locale = get_locale();
|
$locale = is_admin() ? get_user_locale() : get_locale();
|
||||||
$mofile = "{$domain}-{$locale}.mo";
|
$mofile = "{$domain}-{$locale}.mo";
|
||||||
|
|
||||||
if ( in_array( WP_LANG_DIR . '/plugins/' . $mofile, $cached_mofiles ) ) {
|
if ( in_array( WP_LANG_DIR . '/plugins/' . $mofile, $cached_mofiles ) ) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-beta1-39126';
|
$wp_version = '4.7-beta1-39127';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue