Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#46230 closed defect (bug) (duplicate)

Calling `switch_to_locale()` fails to load plugin translations on subsequent calls

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


In short, calling switch_to_locale() followed by restore_previous_locale() followed by switch_to_locale() fails to reload plugin text-domain strings. It appears to work as expected with the default text-domain however.

An example in code (see unit test attached).

$english_text_expected = __( 'Testing', 'textdomain' );
// returns 'Testing'

switch_to_locale( 'de_DE' );
$german_expected = __( 'Testing', 'textdomain' );
// returns 'Testen'
restore_previous_locale(); // Reset to English.

switch_to_locale( 'de_DE' );
$german_expected_again = __( 'Testing', 'textdomain' );
// returns 'Testing' - No translation?

Attachments (1)

46230.unit-test.diff (1.5 KB) - added by dd32 5 years ago.

Download all attachments as: .zip

Change History (2)

5 years ago

#1 @ocean90
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #39210.

Note: See TracTickets for help on using tickets.