Skip to content

Planet 8081 fix translations loaded too early#2851

Open
sagarsdeshmukh wants to merge 2 commits intomainfrom
PLANET-8081-fix-translations-loaded-too-early
Open

Planet 8081 fix translations loaded too early#2851
sagarsdeshmukh wants to merge 2 commits intomainfrom
PLANET-8081-fix-translations-loaded-too-early

Conversation

@sagarsdeshmukh
Copy link
Member

@sagarsdeshmukh sagarsdeshmukh commented Jan 14, 2026

Summary

  • When switching the language to pt_BR, the following notice is triggered:

Notice: A função _load_textdomain_just_in_time foi chamada <strong>incorretamente</strong>. O carregamento da tradução para o domínio <code>planet4-master-theme-backend</code> foi ativado muito cedo. Isso geralmente é um indicador de que algum código no plugin ou tema está sendo executado muito cedo. As traduções devem ser carregadas na ação <code>init</code> ou mais tarde. Leia como <a href="https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/ ">Depurar o WordPress</a> para mais informações. (Esta mensagem foi adicionada na versão 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6121

  • The notice occurs because translation functions such as __() are being executed before the text domain translations are loaded.

  • The issue is caused by the MasterSite and MediaReplacer classes calling the __() function too early in the lifecycle.


Ref:
https://greenpeace-planet4.atlassian.net/browse/PLANET-8081

Testing

  • In the local development environment, install the pt_BR language and activate it
npx wp-env run cli wp language core install pt_BR
npx wp-env run cli wp language core activate pt_BR
  • Check for the above mentioned notice
  • With this PR applied, the notice should be fixed and no longer appear

@sagarsdeshmukh sagarsdeshmukh marked this pull request as ready for review January 14, 2026 08:08
planet-4 added a commit to greenpeace/planet4-test-mars that referenced this pull request Jan 14, 2026
/unhold f672106c-0590-4009-8a5b-f65424381803
@planet-4
Copy link
Contributor

Test instance is ready 🚀

🌑 mars | admin | blocks report | CircleCI | composer-local.json

⌚ 2026.01.14 08:16:57

Copy link
Contributor

@mardelnet mardelnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @sagarsdeshmukh, can you please add to the testing instructions the steps to install the pt_BR language and activate it?

Copy link
Contributor

@mardelnet mardelnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sagarsdeshmukh, I cannot replicate the error you're trying to fix.
On my local instance, using the main branch and the pt_BR language, the website behaves normally.

However, I still can see this translation issue produced by the WP Stateless plugin:
It seems that the issue with the plugin was solved in version 4.2.1
cc @comzeradd

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the stateless-media domain was triggered too early. 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](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/) for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6131 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-includes/functions.php on line 7182 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-admin/admin-header.php on line 14

@sagarsdeshmukh
Copy link
Member Author

sagarsdeshmukh commented Jan 15, 2026

@sagarsdeshmukh, I cannot replicate the error you're trying to fix. On my local instance, using the main branch and the pt_BR language, the website behaves normally.

However, I still can see this translation issue produced by the WP Stateless plugin: It seems that the issue with the plugin was solved in version 4.2.1 cc @comzeradd

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the stateless-media domain was triggered too early. 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](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/) for more information. (This message was added in version 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6131 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-includes/functions.php on line 7182 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-admin/admin-header.php on line 14

Hmm, I double-checked, and the notice is indeed not reproducible.
I then checked the changes that were previously causing this notice, and it gets reproduced when we load translations from the WordPress root language directory.

If you’d like to verify this, you can use the following commands from the local environment root directory(This creates a symlink of the language directory into the WordPress root languages/themes directory.):

cd planet4/languages
ln -s ../themes/planet4-master-theme/languages themes

Since we’re not currently loading translations from the WP root directory, the changes aren’t strictly required, but they still look good to have. What do you think?

@mardelnet
Copy link
Contributor

Hmm, I double-checked, and the notice is indeed not reproducible. I then checked the changes that were previously causing this notice, and it gets reproduced when we load translations from the WordPress root language directory.

If you’d like to verify this, you can use the following commands from the local environment root directory(This creates a symlink of the language directory into the WordPress root languages/themes directory.):

cd planet4/languages
ln -s ../themes/planet4-master-theme/languages themes

Since we’re not currently loading translations from the WP root directory, the changes aren’t strictly required, but they still look good to have. What do you think?

Thanks @sagarsdeshmukh
After running the commands you shared, the following notice arises when the language pt_BR is activated, even using this PR's branch. I tried with some other languages, and the notice's gone.

Notice: A função _load_textdomain_just_in_time foi chamada incorretamente. O carregamento da tradução para o domínio planet4-master-theme-backend foi ativado muito cedo. Isso geralmente é um indicador de que algum código no plugin ou tema está sendo executado muito cedo. As traduções devem ser carregadas na ação init ou mais tarde. Leia como [Depurar o WordPress](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/) para mais informações. (Esta mensagem foi adicionada na versão 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6131 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-includes/functions.php on line 7182 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-admin/admin-header.php on line 14

@sagarsdeshmukh
Copy link
Member Author

Hmm, I double-checked, and the notice is indeed not reproducible. I then checked the changes that were previously causing this notice, and it gets reproduced when we load translations from the WordPress root language directory.
If you’d like to verify this, you can use the following commands from the local environment root directory(This creates a symlink of the language directory into the WordPress root languages/themes directory.):

cd planet4/languages
ln -s ../themes/planet4-master-theme/languages themes

Since we’re not currently loading translations from the WP root directory, the changes aren’t strictly required, but they still look good to have. What do you think?

Thanks @sagarsdeshmukh After running the commands you shared, the following notice arises when the language pt_BR is activated, even using this PR's branch. I tried with some other languages, and the notice's gone.

Notice: A função _load_textdomain_just_in_time foi chamada incorretamente. O carregamento da tradução para o domínio planet4-master-theme-backend foi ativado muito cedo. Isso geralmente é um indicador de que algum código no plugin ou tema está sendo executado muito cedo. As traduções devem ser carregadas na ação init ou mais tarde. Leia como [Depurar o WordPress](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/) para mais informações. (Esta mensagem foi adicionada na versão 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6131 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-includes/functions.php on line 7182 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-admin/admin-header.php on line 14

Which other language you tried? I will check

@mardelnet
Copy link
Contributor

Hmm, I double-checked, and the notice is indeed not reproducible. I then checked the changes that were previously causing this notice, and it gets reproduced when we load translations from the WordPress root language directory.
If you’d like to verify this, you can use the following commands from the local environment root directory(This creates a symlink of the language directory into the WordPress root languages/themes directory.):

cd planet4/languages
ln -s ../themes/planet4-master-theme/languages themes

Since we’re not currently loading translations from the WP root directory, the changes aren’t strictly required, but they still look good to have. What do you think?

Thanks @sagarsdeshmukh After running the commands you shared, the following notice arises when the language pt_BR is activated, even using this PR's branch. I tried with some other languages, and the notice's gone.

Notice: A função _load_textdomain_just_in_time foi chamada incorretamente. O carregamento da tradução para o domínio planet4-master-theme-backend foi ativado muito cedo. Isso geralmente é um indicador de que algum código no plugin ou tema está sendo executado muito cedo. As traduções devem ser carregadas na ação init ou mais tarde. Leia como [Depurar o WordPress](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/) para mais informações. (Esta mensagem foi adicionada na versão 6.7.0.) in /var/www/html/wp-includes/functions.php on line 6131 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-includes/functions.php on line 7182 Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/wp-includes/functions.php:6131) in /var/www/html/wp-admin/admin-header.php on line 14

Which other language you tried? I will check

Many, randomly, but mostly English.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants