load_script_textdomain

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

WordPress Version: 6.3

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return string|false The translated strings in JSON encoding on success,
 *                      false if the script textdomain could not be loaded.
 */
function load_script_textdomain($handle, $domain = 'default', $path = '')
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ('default' === $domain) ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && str_starts_with($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $plugins_url = wp_parse_url(plugins_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if ((!isset($content_url['path']) || str_starts_with($src_url['path'], $content_url['path'])) && (!isset($src_url['host']) || !isset($content_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        if (isset($content_url['path'])) {
            $relative = substr($src_url['path'], strlen($content_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        // Remove plugins/<plugin name> or themes/<theme name>.
        $relative = implode('/', $relative);
    } elseif ((!isset($plugins_url['path']) || str_starts_with($src_url['path'], $plugins_url['path'])) && (!isset($src_url['host']) || !isset($plugins_url['host']) || $src_url['host'] === $plugins_url['host'])) {
        // Make the src relative the specific plugin.
        if (isset($plugins_url['path'])) {
            $relative = substr($src_url['path'], strlen($plugins_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/plugins';
        $relative = array_slice($relative, 1);
        // Remove <plugin name>.
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || !isset($site_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (str_starts_with($src_url['path'], trailingslashit($site_url['path']))) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string|false $relative The relative path of the script. False if it could not be determined.
     * @param string       $src      The full source URL of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (str_ends_with($relative, '.min.js')) {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: 6.1

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return string|false The translated strings in JSON encoding on success,
 *                      false if the script textdomain could not be loaded.
 */
function load_script_textdomain($handle, $domain = 'default', $path = '')
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ('default' === $domain) ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $plugins_url = wp_parse_url(plugins_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if ((!isset($content_url['path']) || strpos($src_url['path'], $content_url['path']) === 0) && (!isset($src_url['host']) || !isset($content_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        if (isset($content_url['path'])) {
            $relative = substr($src_url['path'], strlen($content_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        // Remove plugins/<plugin name> or themes/<theme name>.
        $relative = implode('/', $relative);
    } elseif ((!isset($plugins_url['path']) || strpos($src_url['path'], $plugins_url['path']) === 0) && (!isset($src_url['host']) || !isset($plugins_url['host']) || $src_url['host'] === $plugins_url['host'])) {
        // Make the src relative the specific plugin.
        if (isset($plugins_url['path'])) {
            $relative = substr($src_url['path'], strlen($plugins_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/plugins';
        $relative = array_slice($relative, 1);
        // Remove <plugin name>.
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || !isset($site_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string|false $relative The relative path of the script. False if it could not be determined.
     * @param string       $src      The full source URL of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: 5.7

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return string|false The translated strings in JSON encoding on success,
 *                      false if the script textdomain could not be loaded.
 */
function load_script_textdomain($handle, $domain = 'default', $path = null)
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ('default' === $domain) ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $plugins_url = wp_parse_url(plugins_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if ((!isset($content_url['path']) || strpos($src_url['path'], $content_url['path']) === 0) && (!isset($src_url['host']) || !isset($content_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        if (isset($content_url['path'])) {
            $relative = substr($src_url['path'], strlen($content_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        // Remove plugins/<plugin name> or themes/<theme name>.
        $relative = implode('/', $relative);
    } elseif ((!isset($plugins_url['path']) || strpos($src_url['path'], $plugins_url['path']) === 0) && (!isset($src_url['host']) || !isset($plugins_url['host']) || $src_url['host'] === $plugins_url['host'])) {
        // Make the src relative the specific plugin.
        if (isset($plugins_url['path'])) {
            $relative = substr($src_url['path'], strlen($plugins_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/plugins';
        $relative = array_slice($relative, 1);
        // Remove <plugin name>.
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || !isset($site_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string|false $relative The relative path of the script. False if it could not be determined.
     * @param string       $src      The full source URL of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: 5.6

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return string|false False if the script textdomain could not be loaded, the translated strings
 *                      in JSON encoding otherwise.
 */
function load_script_textdomain($handle, $domain = 'default', $path = null)
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ('default' === $domain) ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $plugins_url = wp_parse_url(plugins_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if ((!isset($content_url['path']) || strpos($src_url['path'], $content_url['path']) === 0) && (!isset($src_url['host']) || !isset($content_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        if (isset($content_url['path'])) {
            $relative = substr($src_url['path'], strlen($content_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        // Remove plugins/<plugin name> or themes/<theme name>.
        $relative = implode('/', $relative);
    } elseif ((!isset($plugins_url['path']) || strpos($src_url['path'], $plugins_url['path']) === 0) && (!isset($src_url['host']) || !isset($plugins_url['host']) || $src_url['host'] === $plugins_url['host'])) {
        // Make the src relative the specific plugin.
        if (isset($plugins_url['path'])) {
            $relative = substr($src_url['path'], strlen($plugins_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/plugins';
        $relative = array_slice($relative, 1);
        // Remove <plugin name>.
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || !isset($site_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string|false $relative The relative path of the script. False if it could not be determined.
     * @param string       $src      The full source URL of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: 5.4

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 * @return string|false False if the script textdomain could not be loaded, the translated strings
 *                      in JSON encoding otherwise.
 */
function load_script_textdomain($handle, $domain = 'default', $path = null)
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ('default' === $domain) ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $plugins_url = wp_parse_url(plugins_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if ((!isset($content_url['path']) || strpos($src_url['path'], $content_url['path']) === 0) && (!isset($src_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        if (isset($content_url['path'])) {
            $relative = substr($src_url['path'], strlen($content_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        // Remove plugins/<plugin name> or themes/<theme name>.
        $relative = implode('/', $relative);
    } elseif ((!isset($plugins_url['path']) || strpos($src_url['path'], $plugins_url['path']) === 0) && (!isset($src_url['host']) || $src_url['host'] === $plugins_url['host'])) {
        // Make the src relative the specific plugin.
        if (isset($plugins_url['path'])) {
            $relative = substr($src_url['path'], strlen($plugins_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/plugins';
        $relative = array_slice($relative, 1);
        // Remove <plugin name>.
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string|false $relative The relative path of the script. False if it could not be determined.
     * @param string       $src      The full source URL of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: 5.3

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 *
 * @return false|string False if the script textdomain could not be loaded, the translated strings
 *                      in JSON encoding otherwise.
 */
function load_script_textdomain($handle, $domain = 'default', $path = null)
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ($domain === 'default') ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $plugins_url = wp_parse_url(plugins_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if ((!isset($content_url['path']) || strpos($src_url['path'], $content_url['path']) === 0) && (!isset($src_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        if (isset($content_url['path'])) {
            $relative = substr($src_url['path'], strlen($content_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        // Remove plugins/<plugin name> or themes/<theme name>.
        $relative = implode('/', $relative);
    } elseif ((!isset($plugins_url['path']) || strpos($src_url['path'], $plugins_url['path']) === 0) && (!isset($src_url['host']) || $src_url['host'] === $plugins_url['host'])) {
        // Make the src relative the specific plugin.
        if (isset($plugins_url['path'])) {
            $relative = substr($src_url['path'], strlen($plugins_url['path']));
        } else {
            $relative = $src_url['path'];
        }
        $relative = trim($relative, '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/plugins';
        $relative = array_slice($relative, 1);
        // Remove <plugin name>.
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string $relative The relative path of the script. False if it could not be determined.
     * @param string $src      The full source url of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: 5.1

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 * @since 5.1.0 The `$domain` parameter was made optional.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain Optional. Text domain. Default 'default'.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 *
 * @return false|string False if the script textdomain could not be loaded, the translated strings
 *                      in JSON encoding otherwise.
 */
function load_script_textdomain($handle, $domain = 'default', $path = null)
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ($domain === 'default') ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if (strpos($src_url['path'], $content_url['path']) === 0 && (!isset($src_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        $relative = trim(substr($src_url['path'], strlen($content_url['path'])), '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string $relative The relative path of the script. False if it could not be determined.
     * @param string $src      The full source url of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: .20

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain The text domain.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 *
 * @return false|string False if the script textdomain could not be loaded, the translated strings
 *                      in JSON encoding otherwise.
 */
function load_script_textdomain($handle, $domain, $path = null)
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ($domain === 'default') ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if (strpos($src_url['path'], $content_url['path']) === 0 && (!isset($src_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        $relative = trim(substr($src_url['path'], strlen($content_url['path'])), '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string $relative The relative path of the script. False if it could not be determined.
     * @param string $src      The full source url of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: 0.2

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain The text domain.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 *
 * @return false|string False if the script textdomain could not be loaded, the translated strings
 *                      in JSON encoding otherwise.
 */
function load_script_textdomain($handle, $domain, $path = null)
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ($domain === 'default') ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path && file_exists($path . '/' . $handle_filename)) {
        return load_script_translations($path . '/' . $handle_filename, $handle, $domain);
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if (strpos($src_url['path'], $content_url['path']) === 0 && (!isset($src_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        $relative = trim(substr($src_url['path'], strlen($content_url['path'])), '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string $relative The relative path of the script. False if it could not be determined.
     * @param string $src      The full source url of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path && file_exists($path . '/' . $md5_filename)) {
        return load_script_translations($path . '/' . $md5_filename, $handle, $domain);
    }
    if (file_exists($languages_path . '/' . $md5_filename)) {
        return load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: .10

/**
 * Loads the script translated strings.
 *
 * @since 5.0.0
 * @since 5.0.2 Uses load_script_translations() to load translation data.
 *
 * @see WP_Scripts::set_translations()
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain The text domain.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 *
 * @return false|string False if the script textdomain could not be loaded, the translated strings
 *                      in JSON encoding otherwise.
 */
function load_script_textdomain($handle, $domain, $path = null)
{
    $wp_scripts = wp_scripts();
    if (!isset($wp_scripts->registered[$handle])) {
        return false;
    }
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ($domain === 'default') ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $handle_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $src = $wp_scripts->registered[$handle]->src;
    if (!preg_match('|^(https?:)?//|', $src) && !($wp_scripts->content_url && 0 === strpos($src, $wp_scripts->content_url))) {
        $src = $wp_scripts->base_url . $src;
    }
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if (strpos($src_url['path'], $content_url['path']) === 0 && (!isset($src_url['host']) || $src_url['host'] === $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        $relative = trim(substr($src_url['path'], strlen($content_url['path'])), '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || $src_url['host'] === $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], trailingslashit($site_url['path'])) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src_url['path'], strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    /**
     * Filters the relative path of scripts used for finding translation files.
     *
     * @since 5.0.2
     *
     * @param string $relative The relative path of the script. False if it could not be determined.
     * @param string $src      The full source url of the script.
     */
    $relative = apply_filters('load_script_textdomain_relative_path', $relative, $src);
    // If the source is not from WP.
    if (false === $relative) {
        return load_script_translations(false, $handle, $domain);
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path) {
        $translations = load_script_translations($path . '/' . $md5_filename, $handle, $domain);
        if ($translations) {
            return $translations;
        }
    }
    $translations = load_script_translations($languages_path . '/' . $md5_filename, $handle, $domain);
    if ($translations) {
        return $translations;
    }
    return load_script_translations(false, $handle, $domain);
}

WordPress Version: 5.0

/**
 * Load the script translated strings.
 *
 * @see WP_Scripts::set_translations()
 * @link https://core.trac.wordpress.org/ticket/45103
 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
 *
 * @since 5.0.0
 *
 * @param string $handle Name of the script to register a translation domain to.
 * @param string $domain The textdomain.
 * @param string $path   Optional. The full file path to the directory containing translation files.
 *
 * @return false|string False if the script textdomain could not be loaded, the translated strings
 *                      in JSON encoding otherwise.
 */
function load_script_textdomain($handle, $domain, $path = null)
{
    global $wp_scripts;
    $path = untrailingslashit($path);
    $locale = determine_locale();
    // If a path was given and the handle file exists simply return it.
    $file_base = ($domain === 'default') ? $locale : ($domain . '-' . $locale);
    $handle_filename = $file_base . '-' . $handle . '.json';
    if ($path && file_exists($path . '/' . $handle_filename)) {
        return file_get_contents($path . '/' . $handle_filename);
    }
    $obj = $wp_scripts->registered[$handle];
    /** This filter is documented in wp-includes/class.wp-scripts.php */
    $src = esc_url(apply_filters('script_loader_src', $obj->src, $handle));
    $relative = false;
    $languages_path = WP_LANG_DIR;
    $src_url = wp_parse_url($src);
    $content_url = wp_parse_url(content_url());
    $site_url = wp_parse_url(site_url());
    // If the host is the same or it's a relative URL.
    if (strpos($src_url['path'], $content_url['path']) === 0 && (!isset($src_url['host']) || $src_url['host'] !== $content_url['host'])) {
        // Make the src relative the specific plugin or theme.
        $relative = trim(substr($src, strlen($content_url['path'])), '/');
        $relative = explode('/', $relative);
        $languages_path = WP_LANG_DIR . '/' . $relative[0];
        $relative = array_slice($relative, 2);
        $relative = implode('/', $relative);
    } elseif (!isset($src_url['host']) || $src_url['host'] !== $site_url['host']) {
        if (!isset($site_url['path'])) {
            $relative = trim($src_url['path'], '/');
        } elseif (strpos($src_url['path'], $site_url['path']) === 0) {
            // Make the src relative to the WP root.
            $relative = substr($src, strlen($site_url['path']));
            $relative = trim($relative, '/');
        }
    }
    // If the source is not from WP.
    if (false === $relative) {
        return false;
    }
    // Translations are always based on the unminified filename.
    if (substr($relative, -7) === '.min.js') {
        $relative = substr($relative, 0, -7) . '.js';
    }
    $md5_filename = $file_base . '-' . md5($relative) . '.json';
    if ($path && file_exists($path . '/' . $md5_filename)) {
        return file_get_contents($path . '/' . $md5_filename);
    }
    if (file_exists($languages_path . '/' . $md5_filename)) {
        return file_get_contents($languages_path . '/' . $md5_filename);
    }
    return false;
}