[wp-trac] [WordPress Trac] #45441: wp_set_script_translations() does not support text domains other than "messages"
WordPress Trac
noreply at wordpress.org
Wed Nov 28 11:12:37 UTC 2018
#45441: wp_set_script_translations() does not support text domains other than
"messages"
--------------------------+-----------------------------
Reporter: swissspidy | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version: 5.0
Severity: normal | Keywords:
Focuses: javascript |
--------------------------+-----------------------------
I'm working on some WP-CLI tooling for the new JS I18N stuff we added in
#45103.
While doing so I noticed that `\WP_Scripts::print_translations()` assumes
that strings are in `locale_data.messages`. However, `messages` is just
the default text domain of a Jed translation file.
Since Jed JSON files can contain translations for multiple text domains,
one might want to combine all translations into one for easier
maintenance. Especially with #45425.
See https://messageformat.github.io/Jed/ for examples of how these JSON
files can look like.
Here's an example from my current WP-CLI script:
{{{#!json
{
"translation-revision-date": "2018-10-21 17:21+0200",
"generator": "WP-CLI\/2.1.0-alpha-c44d019",
"domain": "foo-plugin",
"locale_data": {
"foo-plugin": {
"": {
"domain": "foo-plugin",
"lang": "de_DE",
"plural-forms": "nplurals=2; plural=(n != 1);"
},
"Source": [
"Quelle"
],
"URL": [
"URL"
],
"block name\\u0004Recommendation": [
"Empfehlung"
]
}
}
}
}}}
You'll get the same result when using the
[https://www.npmjs.com/package/po2json po2json npm script] with the
`--domain` argument.
IMO the inline JS added by `\WP_Scripts::print_translations()` should
check whether `locale_data.$text_domain` exists and fall back to
`locale_data.messages` otherwise.
Also can't hurt to `esc_js()` the variables there.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45441>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list