[wp-trac] [WordPress Trac] #43985: Privacy: The user request email should be sent in the user language

WordPress Trac noreply at wordpress.org
Sat Aug 4 02:04:36 UTC 2018


#43985: Privacy: The user request email should be sent in the user language
-------------------------------------+-------------------------------------
 Reporter:  Chouby                   |       Owner:  desrosj
     Type:  defect (bug)             |      Status:  accepted
 Priority:  normal                   |   Milestone:  4.9.9
Component:  I18N                     |     Version:  4.9.6
 Severity:  normal                   |  Resolution:
 Keywords:  has-patch needs-testing  |     Focuses:  administration,
  has-unit-tests                     |  privacy
-------------------------------------+-------------------------------------

Comment (by earnjam):

 Ok, I think I figured out the issue.

 `get_locale()` tries to use the global `$locale` value first. If it's not
 set, it works down a list checking other things like `WPLANG` constant or
 the `WPLANG` option, eventually settling on `en_US` if there is no other
 choice.

 When it figures out the locale, it updates the global `$locale` for future
 use. This global was getting set to `en_US` early on and then persisting
 across tests, meaning that any check of `get_locale()` was returning that
 `en_US` value.

 `switch_to_locale()` only does something if the locale passed to it is
 different than the value of `get_locale()` outside of the admin. Inside
 the admin, it only switches if it's different than the locale of the
 current user.

 So on our case, we had 2 globals throwing everything off here.

 1. `$current_screen->id` was always set to `front` because of the tests at
 the end of `Tests_Locale_Switcher` setting it and these tests not
 resetting it to anything else. This caused `is_admin()` to be false for
 all our tests, making `switch_locale()` always determine whether to change
 based of the return of `get_locale()` and not necessarily the current
 user.
 2. The `$locale` global was always set to `en_US` and not being updated,
 causing `get_locale()` to return the wrong locale after it was supposed to
 have been switched using the `WPLANG` option.

 Basically we just need to add `unset( $GLOBALS['locale']` and
 `set_current_screen( 'dashboard' )` to the `setUp()` function to make sure
 those are consistent across tests.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43985#comment:39>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list