wp_set_script_translations

The timeline below displays how wordpress function wp_set_script_translations has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Sets translated strings for a script.
 *
 * Works only if the script has already been registered.
 *
 * @see WP_Scripts::set_translations()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 5.0.0
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @param string $handle Script handle the textdomain will be attached to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return bool True if the text domain was successfully localized, false otherwise.
 */
function wp_set_script_translations($handle, $domain = 'default', $path = '')
{
    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);
}

WordPress Version: 5.9

/**
 * Sets translated strings for a script.
 *
 * Works only if the script has already been registered.
 *
 * @see WP_Scripts::set_translations()
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 5.0.0
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @param string $handle Script handle the textdomain will be attached to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return bool True if the text domain was successfully localized, false otherwise.
 */
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);
}

WordPress Version: 5.5

/**
 * 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
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @param string $handle Script handle the textdomain will be attached to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return bool True if the text domain was successfully localized, false otherwise.
 */
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);
}

WordPress Version: 5.1

/**
 * 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
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @param string $handle Script handle the textdomain will be attached to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return bool True if the text domain was successfully localized, false otherwise.
 */
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__);
        return false;
    }
    return $wp_scripts->set_translations($handle, $domain, $path);
}

WordPress Version: 5.0

/**
 * 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);
}