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

Sets translated strings for a script.

Description Description

Works only if the script has already been added.

See also See also

Top ↑

Parameters Parameters


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


(string) (Optional) Text domain.

Default value: 'default'


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

Default value: null

Top ↑

Return Return

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

Top ↑

Source 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

Version Description
5.1.0 The $domain parameter was made optional.
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Ronald Huereca

    If you have to generate your own JSON language pack files, use WP CLI to generate your JSON file for you. Just navigate to your plugin folder and run the following command.

    wp i18n make-json languages

    Then set the language folder in wp_set_script_translations

    wp_set_script_translations( 'wp-presenter-pro-js', 'wp-presenter-pro', plugin_dir_path( __FILE__ ) . 'languages' );

    Warning: If someone translates your plugin with the same locale on the WordPress Plugin Directory, the language will not show up if using the third argument.

You must log in before being able to contribute a note or feedback.