Opened 2 years ago
Closed 23 months ago
#57116 closed defect (bug) (fixed)
Plugin translations not loaded after calling `switch_to_locale()`
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 6.2 | Priority: | normal |
Severity: | normal | Version: | 6.1 |
Component: | I18N | Keywords: | has-patch has-unit-tests commit fixed-major |
Focuses: | Cc: |
Description
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 $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.
- Install the User Switching plugin
- Install the Italian language pack for core
- Visit the Updates screen and update translations for plugins
- Add an Administrator user with their language set to
it_IT
- Add an Author user with their language set to
en_US
- Log in as the admin user
- Switch to the Author user
- Observe the confirmation message is shown in English instead of Italian
Change History (12)
This ticket was mentioned in PR #3640 on WordPress/wordpress-develop by @swissspidy.
2 years ago
#3
- Keywords has-unit-tests added
Try to be less smart with the cache in the has()
method and actually do what it’s supposed to do:
Determine whether any MO file paths are available for the domain, regardless of locale.
To-do
- [ ] Write better tests that better capture the bug from the minimal code to reproduce
Trac ticket: https://core.trac.wordpress.org/ticket/57116
This ticket was mentioned in PR #3640 on WordPress/wordpress-develop by @swissspidy.
2 years ago
#4
Try to be less smart with the cache in the has()
method and actually do what it’s supposed to do:
Determine whether any MO file paths are available for the domain, regardless of locale.
To-do
- [ ] Write better tests that better capture the bug from the minimal code to reproduce
Trac ticket: https://core.trac.wordpress.org/ticket/57116
#5
@
2 years ago
- Milestone changed from Awaiting Review to 6.1.2
I was able to reproduce this and saw how the cache wasn't working as intended for this use case. There's a draft PR to fix this, but I have yet to write better tests that actually catch this, as none of the existing ones have done so unfortunately.
@johnbillion commented on PR #3640:
2 years ago
#6
Tested this locally and it fixes the issue in the User Switching plugin 👍
@swissspidy commented on PR #3640:
2 years ago
#9
Committed in https://core.trac.wordpress.org/changeset/55010
#10
@
2 years ago
- Keywords fixed-major added
- Resolution fixed deleted
- Status changed from closed to reopened
Haven't checked yet, but this might have to do with using
load_plugin_textdomain()
but not having any actual translation files in thelanguages
folder:https://github.com/johnbillion/user-switching/blob/ccbc248a1e5f9db44e207f7113c96dbe409c14ac/user-switching.php#L168
Does the switching work once you remove that call?