FAQ: Why do I see warnings that translations are loaded too early?
You're seeing these PHP notices in your logs:
Function _load_textdomain_just_in_time was called <strong>incorrectly</strong>.
Translation loading for the <code>foo</code> domain was triggered too early.
The message goes on to explain itself a bit:
This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the
init
action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.)
The message comes from WordPress. Loco Translate can't fix anything here, but these notices are very useful.
What does it mean?
It means that a plugin or theme is trying to use translations before all plugins have initialized. As soon as translations are requested, they will be loaded by WordPress. If that happens too early, then other plugins may not be around in order to do their job.
In the case of Loco Translate - it's job is to load custom translation files that WordPress doesn't know about. It can't do that if it's not running yet.
Is it causing a problem?
If you're having a problem displaying custom translations, then it's highly likely to be related. See the FAQ: Why don't translations load from the custom folder?
If the text domain mentioned seems to be working fine, then maybe it's not causing a problem. However, it may be working only by luck, so is still worth investigating.
Which plugin is responsible?
The text domain appears in the message text ("foo"
in our example). Often this will be the short name (slug) of the theme or plugin making the early calls,
but there are some important things to note about that:
The text domain isn't always the same name as the plugin (or theme). Some plugins bundle numerous other things, such as frameworks, or even other plugins.
Any plugin can request translations from any other plugin. e.g. WooCommerce add-ons often use translations in the
woocommerce
text domain in addition to their own.Likewise for themes: It's common for child themes to request translations in their parent theme.
Tip: If you plan to approach a developer about this oversight, be mindful that the actual code responsible may be in another plugin.
How do I make the notice go away?
Only the plugin (or theme) making early use of translations can make the root cause go away, but if you're sure the notice can be ignored, then you could switch off WP_DEBUG
.
This will suppress WordPress's _doing_it_wrong
notices.