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

WordPress Trac noreply at wordpress.org
Mon Oct 2 21:52:09 UTC 2017


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

 * keywords:  has-patch needs-unit-tests needs-refresh => has-patch needs-
     unit-tests dev-feedback


Comment:

 Just spent some time on adding a new registry class for storing these
 paths.

 The `load_*_textdomain()` functions now don't actually load any
 translations. This only happens when calling `translate()`.

 Thus, things like accessing `$l10n['default']->headers['Language']` just
 after switching  locales doesn't work unless you call
 `load_*_textdomain()` / `get_translations_for_domain()` between that.
 That's why the
 `test_switch_to_different_site_locale_if_user_locale_is_set()` test is
 failing right now. If BC in this area is a big concern, `$l10n` could be
 turned into an object with magic getters. When someone accesses
 `$l10n['default']->headers`, we would manually load the translations for
 that.

 If there's interest, I can put this up on GitHub as a PR for
 collaboration.

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


More information about the wp-trac mailing list