Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 17 months ago

#60891 closed defect (bug) (fixed)

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

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

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 (11)

#1 @swissspidy
3 years ago

  • Keywords has-patch has-unit-tests added
  • Milestone Awaiting Review → 6.6
  • Version 6.4.3 → 5.0

Can confirm.

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


3 years 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
3 years 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
3 years ago

  • Milestone 6.6 → 6.5.1

Moving to 6.5.1 for visibility

#5 @swissspidy
3 years ago

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

#6 @swissspidy
3 years ago

  • Milestone 6.5.1 → 6.6

#7 @johnbillion
3 years ago

I must be going blind to version numbers

#8 @audrasjb
3 years ago

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

#9 @swissspidy
3 years ago

  • Owner set to swissspidy
  • Resolution → fixed
  • Status new → 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.

#11 @wordpressdotorg
17 months ago

  • Keywords has-test-info added; has-testing-info removed
Note: See TracTickets for help on using tickets.