Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#53097 closed defect (bug) (duplicate)

Registering scripts through block.json dosn't load translation files inside plugins

Reported by: walbo's profile walbo Owned by:
Milestone: Priority: normal
Severity: normal Version: 5.7
Component: I18N Keywords:
Focuses: Cc:

Description

When registering scripts with block.json and adding a textdomain WordPress only checks for translations in the WP_LANG_DIR folder.

This means that blocks will not pick up translations from plugins that have a /language folder with translations.

Should block.json have a domain path option or pick up Domain path from the plugin comment?

Change History (5)

#1 @desrosj
3 years ago

  • Keywords close added

Hi @walbo,

My apologies for missing this one when you initially created it.

I believe that this has been solved over on the Meta Trac: https://meta.trac.wordpress.org/ticket/5737.

Can you confirm?

#2 @desrosj
3 years ago

  • Summary changed from Registering scripts trough block.json dosn't load translation files inside plugins to Registering scripts through block.json dosn't load translation files inside plugins

#3 @walbo
3 years ago

  • Keywords close removed
  • Version changed from trunk to 5.7

Still not solved. Not my best description so I'll explain the problem more in detail.

The issue is with custom plugins not hosted on wp.org, that provides the translated files in a language folder inside the plugin.

All the translations will then be loaded with:

load_plugin_textdomain( 'todo-list', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );

This work as expected and translates all php and block.json strings.

In the plugin the editor script are registered in the block.json with "editorScript": "file:./build/index.js"

In #52301 wp_set_script_translations was added to scripts registered trough block.json:

if ( ! empty( $metadata['textdomain'] ) ) {
        wp_set_script_translations( $script_handle, $metadata['textdomain'] );
}

The problem is that there is no option to set the 3td ($path) argument. The result of this is that WP only checks for json translations in wp-content/languages/plugins/ and never checks the language folder inside the plugin. This means that the editor script string doesn't get translated.

#4 @markhowellsmead
3 years ago

Same problem here. Locating PO and MO files in the plugin's own languages directory doesn't work.

#5 @ocean90
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Closing as a duplicate of #54797 which now has a patch ready for testing.

Note: See TracTickets for help on using tickets.