[wp-trac] [WordPress Trac] #45320: Allow preloading the translations in `load_script_textdomain`
WordPress Trac
noreply at wordpress.org
Fri Nov 9 16:48:31 UTC 2018
#45320: Allow preloading the translations in `load_script_textdomain`
-----------------------------+-----------------------------
Reporter: strategio | Owner: (none)
Type: feature request | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version: 5.0
Severity: critical | Keywords:
Focuses: |
-----------------------------+-----------------------------
**Problem:**
Now that we can translate strings on the JS side and with the introduction
of `wp_set_script_translations`, we have no way to override the
translations coming from the JSON files.
We need a filter allowing to delegate the process of loading the
translations.
**Suggestion:**
Ideally, we could have a filter inside `load_script_textdomain` where we
could provide our own set of translations (as a JED object).
Here's an idea:
{{{#!php
<?php
function load_script_textdomain( $handle, $domain, $path = null ) {
global $wp_scripts;
$json_translations = apply_filters( 'pre_load_script_textdomain',
false, $handle, $domain, $path );
if ( $json_translations ) {
return $json_translations;
}
//...
}
}}}
**Why we need it:**
In WPML, we store the string translations in the DB and we offer the user
the ability to add/edit translations. Apart overwriting the JSON files
(which could be an option, but would also introduce other issues), we have
no way to provide our own translations to the JS script.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/45320>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list