[wp-trac] [WordPress Trac] #57116: Plugin translations not loaded after calling `switch_to_locale()`

WordPress Trac noreply at wordpress.org
Tue Nov 15 13:22:59 UTC 2022


#57116: Plugin translations not loaded after calling `switch_to_locale()`
--------------------------+-----------------------------
 Reporter:  johnbillion   |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  I18N          |    Version:  6.1
 Severity:  normal        |   Keywords:  has-patch
  Focuses:                |
--------------------------+-----------------------------
 I'm still trying to narrow down the issue but it seems that [54682] in 6.1
 caused an issue where plugin translation strings are not loaded after
 calling `switch_to_locale()`. WordPress core translations are correctly
 loaded in the same situation.

 Not yet sure if this is the same issue as #57084.

 == Minimal code to reproduce ==

 Assuming a site that uses `en_US`, a translation file for `it_IT` is
 present, and the relevant translation files in place:

 {{{#!php
 <?php
 $switched_locale = switch_to_locale( 'it_IT' );
 _e( 'My text string', 'my-textdomain' );
 var_dump( $switched_locale );
 }}}

 The locale is correctly switched but the text string is output in the
 original language instead of the target language.

 == Testing with the User Switching plugin ==

 My User Switching plugin includes this functionality and includes
 acceptance tests that started failing with WordPress 6.1. See
 https://github.com/johnbillion/user-
 switching/actions/runs/3470688222/jobs/5799202419 for a failing CI run.

 1. Install [https://wordpress.org/plugins/user-switching/ the User
 Switching plugin]
 2. Install the Italian language pack for core
 3. Visit the Updates screen and update translations for plugins
 4. Add an Administrator user with their language set to `it_IT`
 5. Add an Author user with their language set to `en_US`
 6. Log in as the admin user
 7. Switch to the Author user
 8. Observe the confirmation message is shown in English instead of Italian

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


More information about the wp-trac mailing list