Make WordPress Core

Opened 7 months ago

Closed 7 months ago

Last modified 7 months ago

#60891 closed defect (bug) (fixed)

When plugins have a custom directory, script translations don’t load correctly

Reported by: coreymckrill's profile coreymckrill Owned by: swissspidy's profile swissspidy
Milestone: 6.6 Priority: normal
Severity: normal Version: 5.0
Component: I18N Keywords: has-patch has-unit-tests needs-testing has-testing-info
Focuses: Cc:

Description

This issue was originally reported as a problem with WooCommerce, but it actually appears to be happening in WordPress core itself. If the plugin directory is customized using the WP_PLUGIN_DIR constant (along with WP_PLUGIN_URL), the language packs for plugins still get installed at wp-content/languages/plugins. However, the paths of script translation files are calculated using the custom path instead, and the translations don't load.

To reproduce:

  1. On a fresh WordPress installation, define the WP_PLUGIN_DIR and WP_PLUGIN_URL constants in your wp-config.php file to set a custom directory. Example:
define( 'WP_PLUGIN_DIR', ABSPATH . '/wp-content/mods' );
define( 'WP_PLUGIN_URL', 'https://localhost/wp-content/mods' );
  1. Install and activate a plugin on your site that has script translations. WooCommerce is a good option, but I also confirmed this with Gutenberg, and it should work with any plugin that has script translations. Confirm that the plugin successfully installed into the custom plugin directory.
  2. Install and activate the Query Monitor plugin to make it easier to see which translation files get loaded on a given request.
  3. Switch your site to a locale other than en_US, and then go to Dashboard > Updates to download the language pack for the installed plugins. Confirm that the language pack files successfully install into wp-content/languages/plugins.
  4. Find a WP Admin screen where the plugin's script translation files would be loaded. It's easier if it's a screen that has the admin bar at the top so you can easily access the Query Monitor console.
  5. Open the QM console on that screen, and find the Languages tab. Scroll down the list until you find entries for the text domain of the plugin you installed. Look for the "jed" type, as these are the script translations. Then note that for each script translation file, it makes a few different attempts to load. But instead of trying wp-content/languages/plugins, it tries (in the case of the example directory name used above), wp-content/languages/mods.

Change History (10)

#1 @swissspidy
7 months ago

  • Keywords has-patch has-unit-tests added
  • Milestone changed from Awaiting Review to 6.6
  • Version changed from 6.4.3 to 5.0

Can confirm.

This ticket was mentioned in PR #6346 on WordPress/wordpress-develop by @swissspidy.


7 months ago
#2

Script translations are always in wp-content/languages/plugins, where plugins doesn't change even when wp-content/plugins is relocated.

Trac ticket: https://core.trac.wordpress.org/ticket/60891

#3 @audrasjb
7 months ago

  • Keywords needs-testing has-testing-info added

The patch looks good to me and seems to be working on my side after relocating WP_PLUGIN_DIR.

Assuming that it can be tested more widely and in time for the next minor (see testing instruction provided in the ticket description), should we try to move it to 6.5.1?

#4 @johnbillion
7 months ago

  • Milestone changed from 6.6 to 6.5.1

Moving to 6.5.1 for visibility

#5 @swissspidy
7 months ago

Why 6.5.1? This bug existed since 5.0, it's not a regression in 6.5.

#6 @swissspidy
7 months ago

  • Milestone changed from 6.5.1 to 6.6

#7 @johnbillion
7 months ago

I must be going blind to version numbers

#8 @audrasjb
7 months ago

Uh?! Apologies I wrongly assumed it was introduced by Performant Translation merge 🙃

#9 @swissspidy
7 months ago

  • Owner set to swissspidy
  • Resolution set to fixed
  • Status changed from new to closed

In 57922:

I18N: Always search for script translations in wp-content/languages/plugins.

Previously, when WP_PLUGIN_DIR was set to something other than wp-content/plugins, e.g. wp-content/mods, load_script_textdomain was searching for script translations in wp-content/languages/mods. However, that is incorrect, as WP_PLUGIN_DIR does not affect where translations are stored. The location is always wp-content/languages/plugins.

Props coreymckrill, swissspidy.
Fixes #60891.

Note: See TracTickets for help on using tickets.