wp_set_script_translations() WordPress Function

The wp_set_script_translations() function allows you to specify the translation files for your Javascript files. This is useful if you want to create a multilingual site or if you want to use a translation service to translate your Javascript files into different languages.

wp_set_script_translations( string $handle, string $domain = 'default', string $path = null ) #

Sets translated strings for a script.


Description

Works only if the script has already been registered.

Top ↑

See also


Top ↑

Parameters

$handle

(string)(Required)Script handle the textdomain will be attached to.

$domain

(string)(Optional) Text domain.

Default value: 'default'

$path

(string)(Optional) The full file path to the directory containing translation files.

Default value: null


Top ↑

Return

(bool) True if the text domain was successfully localized, false otherwise.


Top ↑

Source

File: wp-includes/functions.wp-scripts.php

function wp_set_script_translations( $handle, $domain = 'default', $path = null ) {
	global $wp_scripts;

	if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
		_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
		return false;
	}

	return $wp_scripts->set_translations( $handle, $domain, $path );
}


Top ↑

Changelog

Changelog
VersionDescription
5.1.0The $domain parameter was made optional.
5.0.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.