Opened 6 years ago
Closed 6 years ago
#45320 closed enhancement (duplicate)
Allow preloading the translations in `load_script_textdomain`
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 5.0 |
Component: | I18N | Keywords: | needs-patch |
Focuses: | Cc: |
Description
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 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.
Attachments (1)
Change History (4)
#1
@
6 years ago
- Keywords needs-patch added
- Severity changed from critical to normal
- Type changed from feature request to enhancement
Patch to introduce the filter
pre_load_script_textdomain