[wp-trac] [WordPress Trac] #37997: Increase in function calls to get_locale() because of _load_textdomain_just_in_time()

WordPress Trac noreply at wordpress.org
Fri Sep 9 13:43:13 UTC 2016


#37997: Increase in function calls to get_locale() because of
_load_textdomain_just_in_time()
---------------------------------------+--------------------------
 Reporter:  sharkomatic                |       Owner:
     Type:  defect (bug)               |      Status:  new
 Priority:  normal                     |   Milestone:  4.6.2
Component:  I18N                       |     Version:  4.6
 Severity:  normal                     |  Resolution:
 Keywords:  needs-testing needs-patch  |     Focuses:  performance
---------------------------------------+--------------------------

Comment (by sharkomatic):

 Thanks for your reply. I obviously don't have as much knowledge of how the
 code is supposed to function and didn't investigate very thoroughly. And
 you're correct, obviously. unload_textdomain() is the only place I see the
 $l10n_unloaded array being filled, and that's only if $plugin_override is
 true or if unload_textdomain() is called on a domain that is in the $l10n
 array.

 If you instead change get_translations_for_domain() as you suggested to
 return $noop_translations upon first fail, wouldn't it still go through
 the _load_textdomain_just_in_time() process each time anyway (within the
 if statement on line 875)?

 Couldn't you just unload the textdomain where I explicitly added the
 domain to the $l10n_unloaded array in _load_textdomain_just_in_time()?
 That would also require a change to unload_textdomain() to allow the
 domain to be added to the $l10n_unloaded array regardless of whether
 $plugin_override is true or if the domain exists within the $l10n array
 (which in this case would not).

 It seems like it would be even better to check if a textdomain has been
 unloaded before get_translations_for_domain() is called to avoid all those
 extra function calls if we already know there are no translation files for
 a particular domain
 (translate()/translate_with_gettext_context()/_n()/_nx() call
 get_translations_for_domain() which calls _load_textdomain_just_in_time()
 which should be unloading the textdomain). This way, for each domain
 without translations (and which aren't explicitly overriding the WordPress
 translations, that entire function process is only executed once).

 As for @Chouby's suggestion, I have no interest in keeping up with each
 plugin and theme's textdomain and whether they have available translations
 or should be overridden in my own code.

 Again, thanks for your reply. I am leaving my code change in place for
 now, rather than having to change two functions within l10n.php.

 - Steph



 Replying to [comment:4 swissspidy]:
 > > The problem is that if no translation files exist for that textdomain,
 `_load_textdomain_just_in_time()` goes through the entire process each
 time it is called because the domain is never being added to the
 `$l10n_unloaded` array
 >
 > That's not how this array is being used. It is only filled when
 explicitly calling `unload_textdomain()`.
 >
 > We should rather change `get_translations_for_domain()` so that it
 returns `$noop_translations` after the first failed attempt.

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


More information about the wp-trac mailing list