Make WordPress Core


Ignore:
Timestamp:
11/03/2016 08:07:08 PM (9 years ago)
Author:
swissspidy
Message:

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.

File:
1 edited

Legend:

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

    r39070 r39127  
    8989function get_user_locale( $user_id = 0 ) {
    9090    $user = false;
    91     if ( 0 === $user_id ) {
     91    if ( 0 === $user_id && function_exists( 'wp_get_current_user' ) ) {
    9292        $user = wp_get_current_user();
    9393    } elseif ( $user_id instanceof WP_User ) {
     
    711711     * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    712712     */
    713     $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
     713    $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
    714714
    715715    $mofile = $domain . '-' . $locale . '.mo';
     
    745745function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
    746746    /** This filter is documented in wp-includes/l10n.php */
    747     $locale = apply_filters( 'plugin_locale', get_locale(), $domain );
     747    $locale = apply_filters( 'plugin_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
    748748
    749749    $mofile = $domain . '-' . $locale . '.mo';
     
    784784     * @param string $domain Text domain. Unique identifier for retrieving translated strings.
    785785     */
    786     $locale = apply_filters( 'theme_locale', get_locale(), $domain );
     786    $locale = apply_filters( 'theme_locale', is_admin() ? get_user_locale() : get_locale(), $domain );
    787787
    788788    $mofile = $domain . '-' . $locale . '.mo';
     
    866866    }
    867867
    868     $locale = get_locale();
     868    $locale = is_admin() ? get_user_locale() : get_locale();
    869869    $mofile = "{$domain}-{$locale}.mo";
    870870
Note: See TracChangeset for help on using the changeset viewer.