mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-01 19:24:34 +00:00
I18N: Add JavaScript translation support.
Adds the `wp_set_script_translations()` function which registers translations for a JavaScript file. This function takes a handle, domain and optionally a path and ensures JavaScript translation files are loaded if they exist. Merges [43825,43828,43859,43898] from the 5.0 branch to trunk. Props herregroen, atimmer, omarreiss, nerrad, swissspidy, ocean90, georgestephanis. Fixes #45103, #45256. git-svn-id: https://develop.svn.wordpress.org/trunk@44169 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -200,6 +200,32 @@ function wp_localize_script( $handle, $object_name, $l10n ) {
|
||||
return $wp_scripts->localize( $handle, $object_name, $l10n );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets translated strings for a script.
|
||||
*
|
||||
* Works only if the script has already been added.
|
||||
*
|
||||
* @see WP_Scripts::set_translations()
|
||||
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
|
||||
*
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param string $handle Script handle the textdomain will be attached to.
|
||||
* @param string $domain The textdomain.
|
||||
* @param string $path Optional. The full file path to the directory containing translation files.
|
||||
*
|
||||
* @return bool True if the textdomain was successfully localized, false otherwise.
|
||||
*/
|
||||
function wp_set_script_translations( $handle, $domain, $path = null ) {
|
||||
global $wp_scripts;
|
||||
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
|
||||
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
|
||||
return false;
|
||||
}
|
||||
|
||||
return $wp_scripts->set_translations( $handle, $domain, $path );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a registered script.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user