Make WordPress Core

Opened 5 months ago

Closed 6 days ago

#59695 closed defect (bug) (worksforme)

determine_locale ignores get_user_locale() in front end

Reported by: pentatonicfunk's profile pentatonicfunk Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.3.2
Component: I18N Keywords: close
Focuses: Cc:

Description

It works in wp-admin (is_admin) but does not work as expected in front-end

<?php

/**
 * Setup Site language = en_US
 * User language = fr_FR
 */
add_action( 'in_admin_footer', '_print_locale');
add_action( 'wp_footer', '_print_locale');

function _print_locale(){
        ?>
        <div style="text-align: center;">
                <h3>get_user_locale: <?php echo esc_html( get_user_locale() ); ?> </h3> // in both WP-admin and front end it prints fr_FR
                <h3>determine_locale: <?php echo esc_html( determine_locale() ); ?> </h3> // in WP-admin it prints fr_FR, but in front end it prints en_US
        </div>
        <?php
}

the determine_locale it self has is_admin() logic, so maybe there are limitations / caveats of why this purposely skipped in front end ?

there are some discussions here that maybe related: https://core.trac.wordpress.org/ticket/29783

But i look at it as inconsistency, due to WP-admin-bar, it potentially have different language being used, even though the component looks identical between viewed in wp-admin or in front end.

In general i would expect when i set my language settings as X, i would see X in the whole site when im logged in. Except user-generated content of course.

Change History (2)

#1 @swissspidy
5 months ago

  • Keywords close added

This is by design. 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. See https://make.wordpress.org/core/2016/11/07/user-admin-languages-and-locale-switching-in-4-7/ for more details.

As for the toolbar, ideally we would show the toolbar in your locale, but the site in the site's locale. But it's not that easy unfortunately. Follow #38643 on that topic.

#2 @swissspidy
6 days ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.