WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 2 months ago

#53097 new defect (bug)

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

Reported by: walbo Owned by:
Milestone: Awaiting Review 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 (3)

#1 @desrosj
2 months 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
2 months 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
2 months 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.

Note: See TracTickets for help on using tickets.