[wp-trac] [WordPress Trac] #39210: switch_to_locale() unloads all plugin and theme translations

WordPress Trac noreply at wordpress.org
Mon Nov 5 19:34:09 UTC 2018


#39210: switch_to_locale() unloads all plugin and theme translations
-------------------------------------------------+-------------------------
 Reporter:  gchtr                                |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  I18N                                 |     Version:  4.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-unit-tests dev-      |     Focuses:
  feedback                                       |
-------------------------------------------------+-------------------------

Comment (by drzraf):

 @pcfreak30 same couple of hours lost for me too!

 Please devs, at least put a ToDo/Warning/whatever alongside the code for
 `switch_to_locale()`

 Basic use case of what currently fails:
 {{{
 #!php5
 add_action( 'after_setup_theme', function() {
     load_theme_textdomain( 'co', get_template_directory() . '/languages'
 );
 });
 // we need to change locale. Eg, according to page template
 add_action( 'wp', function() {
     if (is_page() && strtolower(get_field('country_code')) == 'es' &&
 FOOBAR) {
     // Only if languages are installed for core (wp-cli language core
 install es_ES)
     switch_to_locale("es_ES");
 }, 10);
 print(__("hello","co")); // expected "hola"
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/39210#comment:15>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list