[wp-trac] [WordPress Trac] #54797: Allow languages path in register_block_type

WordPress Trac noreply at wordpress.org
Wed Oct 26 12:12:15 UTC 2022


#54797: Allow languages path in register_block_type
--------------------------------------+-----------------------
 Reporter:  Rahe                      |       Owner:  gziolo
     Type:  defect (bug)              |      Status:  assigned
 Priority:  normal                    |   Milestone:  6.2
Component:  I18N                      |     Version:  5.5
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+-----------------------

Comment (by felipeelia):

 Hi there!


 What I'm sharing here is the result of some time debugging a problem that
 although not strictly the same as outlined in the ticket seems to be so
 related that doesn't worth a new ticket IMHO. Let me know if you all
 prefer it in a new ticket and I can create that. I also want to ask you to
 excuse me if I missed something obvious here :)

 I got here trying to translate a JS file added via `block.json`'s
 editorScript. In my case, it has a long relative path, like {{{
 file:/../../../../../dist/js/facets-meta-block-script.js }}}


 That seems to be generating a discrepancy between the md5 value while
 creating the .json file and the md5 value actually expected when loading
 translations. Here is some code to (hopefully) clarify it a bit:

 **File creation**

 It seems to use the "real" file name
 [https://meta.trac.wordpress.org/browser/sites/trunk/wordpress.org/public_html
 /wp-content/plugins/wporg-gp-customizations/inc/cli/class-language-
 pack.php#L458 here]. In this case, `dist/js/facets-meta-block-script.js`.

 **File detection**

 Due to the way we are generating the src value
 [https://github.com/WordPress/wordpress-
 develop/blob/49da4afcf03f6eea5aba20b42abc0130fc9e2749/src/wp-
 includes/blocks.php#L143 here], it becomes `https://<domain>/wp-
 content/plugins/elasticpress/assets/js/blocks/facets/taxonomy/../../../../../dist/js
 /facets-block-script.js`. That `assets/js/blocks/facets/taxonomy` is where
 the block.json is located.

 Then in load_script_textdomain, the value used to get an md5 hash
 [https://github.com/WordPress/wordpress-
 develop/blob/49da4afcf03f6eea5aba20b42abc0130fc9e2749/src/wp-
 includes/l10n.php#L1162 here] is actually
 `assets/js/blocks/facets/meta/../../../../../dist/js/facets-meta-block-
 script.js` and not `dist/js/facets-meta-block-script.js` as used during
 the generation step.

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


More information about the wp-trac mailing list