[wp-trac] [WordPress Trac] #50749: wp_set_script_translations() ignores failure when called before script is registered.

WordPress Trac noreply at wordpress.org
Fri Jul 24 05:22:22 UTC 2020


#50749: wp_set_script_translations() ignores failure when called before script is
registered.
--------------------------+-----------------------------
 Reporter:  tellyworth    |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  I18N          |    Version:  5.4
 Severity:  normal        |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 wp_set_script_translations() only works if it's called after the script
 has already been registered. The doc page confirms this:
 https://developer.wordpress.org/reference/functions/wp_set_script_translations/.
 The function does trigger `_doing_it_wrong` when called prior to
 `wp_register_scripts`, but fails silently when called before the specific
 script has been registered.

 In investigating js translation issues in the plugin directory, we
 discovered that it is very common for developers to incorrectly call
 `wp_set_script_translations()` too early. As a result, js translations are
 not correctly loaded for many plugins.

 This would be easily fixed by having `wp_set_script_translations()`
 trigger `_doing_it_wrong` when `$wp_scripts->set_translations()` returns
 false.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50749>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list