[wp-trac] [WordPress Trac] #32879: Live switching Language

WordPress Trac noreply at wordpress.org
Fri Jul 3 14:30:25 UTC 2015


#32879: Live switching Language
-----------------------------+-----------------------------
 Reporter:  Rahe             |      Owner:
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  I18N             |    Version:  4.2.2
 Severity:  normal           |   Keywords:
  Focuses:                   |
-----------------------------+-----------------------------
 Hi,

 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 :

 {{{
 <?php

 Language_Switcher::get_instance()->switch_locale('fr_FR');

 /**
 * Some text to translate in French
 */

 Language_Switcher::get_instance()->restore_locale();
 ?>
 }}}

 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 :)

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


More information about the wp-trac mailing list