[wp-trac] [WordPress Trac] #53097: Registering scripts through block.json dosn't load translation files inside plugins

WordPress Trac noreply at wordpress.org
Mon Jul 19 10:06:16 UTC 2021


#53097: Registering scripts through block.json dosn't load translation files inside
plugins
--------------------------+------------------------------
 Reporter:  walbo         |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  I18N          |     Version:  5.7
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by walbo):

 * keywords:  close =>
 * version:  trunk => 5.7


Comment:

 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:
 {{{#!php
 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:
 {{{#!php
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/53097#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list