[wp-trac] [WordPress Trac] #57123: Make it easier to switch to a user's locale

WordPress Trac noreply at wordpress.org
Wed Nov 16 10:12:57 UTC 2022


#57123: Make it easier to switch to a user's locale
-------------------------+-----------------------------
 Reporter:  swissspidy   |      Owner:  swissspidy
     Type:  enhancement  |     Status:  assigned
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  I18N         |    Version:  4.7
 Severity:  normal       |   Keywords:  needs-patch
  Focuses:               |
-------------------------+-----------------------------
 Locale switching was introduced in #26511 to allow doing things like
 sending emails in the recipient's locale instead of the site's locale.

 That's why we see a lot of code like `switch_to_locale( get_user_locale(
 $user ) )` in core and in plugins.

 Not only is this very repetitive, it also causes limitations when used in
 combination with things like the [https://wordpress.org/plugins/preferred-
 languages Preferred Languages] feature plugin, where one would like to
 fall back to another locale if the desired one is not available.

 That's because the locale switcher lacks context about which user the
 locale is for.

 To improve this, we could introduce a new `switch_to_user_locale( $user )`
 function that a) grabs the user's locale and b) stores the user ID in the
 locale switcher stack so that at each moment in time we know whose locale
 we're supposed to be using.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57123>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list