Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#32879 closed feature request (duplicate)

Live switching Language

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



I'm currently working on a projet where I needed to change the loaded mo to another language.

In my cron I needed to change the locale to a user defined value and then send a mail to him in his/her language, then an another mail to someone else in on another language.

The main problem was I haven't context of the user language an needed to switch the loaded file.

My idea was to hook all load_textdomain, store them in a property and then switch the languages like a wp_switch_blog method but only with locale.

The code unload all textdomain and then try to load the previous stored values.

Since WordPress can store at different places the translation files, at this time this is not possible to only have the path to localized files.

And the Class have to be launched as soon as possible to get all mo files, like in the mu-plugins.

The performances with 11 files wasn't very bad, 0.010 sec to switch the files. But many sites have more !

I use it like this :



* Some text to translate in French


I do not touch the global $locale, just un/loading mo files.

Maybe there is an elegant way to integrate this in core ? Or this is an edge case and not usefull for the other developpers :)

Attachments (1)

switcher.php (2.0 KB) - added by Rahe 9 years ago.
The switcher class

Download all attachments as: .zip

Change History (5)

9 years ago

The switcher class

#1 @ocean90
8 years ago

Related: #29783, #26511.

This ticket was mentioned in Slack in #core-i18n by ocean90. View the logs.

8 years ago

#3 @SergeyBiryukov
8 years ago

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

Hi @Rahe, thanks for the ticket!

#26511 has a similar switch_to_locale() proposal, let's focus on this feature there.

#4 @Rahe
8 years ago


Is this feature will be available on frontend too ?
I'm glad this feature can be merged in core :)

Note: See TracTickets for help on using tickets.