[wp-trac] [WordPress Trac] #39210: switch_to_locale() unloads all plugin and theme translations
WordPress Trac
noreply at wordpress.org
Thu Oct 20 17:45:22 UTC 2022
#39210: switch_to_locale() unloads all plugin and theme translations
-------------------------------------------------+-------------------------
Reporter: gchtr | Owner: ocean90
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 6.1
Component: I18N | Version: 4.7
Severity: normal | Resolution:
Keywords: has-unit-tests has-patch needs-dev- | Focuses:
note |
-------------------------------------------------+-------------------------
Comment (by flixos90):
Replying to [comment:71 swissspidy]:
> We have now already established that there's a bug here causing too many
calls to `load_textdomain()`. Simple as that. No need for detailed
performance analysis for other sites or anything.
I still think it would be interesting to see how the original commit here
affects performance for the scenarios where it already works as expected,
so I did a quick test similar to the previous ones where I compared
6.1-RC2 with 6.1-RC2 with the relevant code replaced with the 6.0.3 code,
just with translation files present.
The difference is small, but consistently visible: With de_DE for example,
with the commit here WordPress took a median of 0.1915s to load, while
without it it was 0.1956s, so roughly 4ms difference. While there is
always fluctuation, this seems to indeed be consistent, so it's good to
see a positive impact of the overall concept.
> Good news is that I have a [https://github.com/WordPress/wordpress-
develop/pull/3506 draft PR] fixing this PR. It's like 99% complete.
>
> Feel free to to check it out. I will continue looking into it myself
when my next workday commences.
I took a look at the PR. I am not too familiar with that code, but it
seems to me that there is a much simpler solution to the problem than what
the PR does: The real problem is in
https://core.trac.wordpress.org/browser/trunk/src/wp-
includes/l10n.php?rev=54654#L762, which I found out due to further
testing: Different than my original assessment where I focused on the
en_US locale, the problem goes actually beyond that: It occurs whenever
translation files are not present locally, which is certainly possible for
even locales that are not en_US (e.g. when a plugin or theme is not
translated yet, or simply when the site has not downloaded the language
packs yet).
Simply adding a `$wp_textdomain_registry->set( $domain, $locale, false );`
above the above line fixes the problem for me, by storing that there is no
translation file in that situation, the same way it is already done when
the translation file cannot be imported.
Potentially this may introduce another problem that I'm unfamiliar with,
but at least the above change is where I would have started.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/39210#comment:72>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list