Opened 4 years ago
Last modified 7 weeks ago
#50749 new defect (bug)
wp_set_script_translations() ignores failure when called before script is registered.
Reported by: | tellyworth | Owned by: | |
---|---|---|---|
Milestone: | Future Release | Priority: | normal |
Severity: | normal | Version: | 5.4 |
Component: | I18N | Keywords: | has-unit-tests needs-patch |
Focuses: | Cc: |
Description
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.
Change History (6)
This ticket was mentioned in PR #466 on WordPress/wordpress-develop by donmhico.
4 years ago
#2
- Keywords has-patch has-unit-tests added; needs-patch removed
Trigger _doing_it_wrong()
when passed $domain
is not a string and if $wp_scripts->set_translations()
returns false
.
Trac ticket: https://core.trac.wordpress.org/ticket/50749
#3
@
4 years ago
@tellyworth would be great if you can check if my patch corrects the issue? Also the $message
passed to _doing_it_wrong
could be improved. Thank you!
Note that
$wp_scripts->set_translations()
will also returnfalse
if the domain is not a string. That would be an easy checck to add towp_set_script_translations
as well.