# _load_script_textdomain_from_src()

URL: https://chugunov.pro/api-wordpress/functions/_load_script_textdomain_from_src/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 7.0.0.

## Сигнатура

```php
_load_script_textdomain_from_src( string $handle, string $src, string $domain, string $path, bool $is_module ): string|false
```

## Описание

Это общая реализация, используемая load_script_textdomain() и load_script_module_textdomain(), чтобы не дублировать логику определения пути и поиска файла.

## Параметры

- `$handle` `string` — обязательный. Имя скрипта или идентификатор модуля скрипта, для которого регистрируется домен перевода.
- `$src` `string` — обязательный. Абсолютный URL исходного кода скрипта или модуля скрипта.
- `$domain` `string` — обязательный. Текстовый домен.
- `$path` `string` — обязательный. Полный путь к каталогу с файлами перевода или пустая строка для использования пути по умолчанию из реестра текстовых доменов.
- `$is_module` `bool` — обязательный. Принадлежит ли исходный код модулю скрипта (true) или классическому скрипту (false).

## Возвращаемое значение

`string|false`

## Исходный код

Файл: `wp-includes/l10n.php:1208`

```php
function _load_script_textdomain_from_src( string $handle, string $src, string $domain, string $path, bool $is_module ) {
	/** @var WP_Textdomain_Registry $wp_textdomain_registry */
	global $wp_textdomain_registry;

	$locale = determine_locale();

	if ( ! $path ) {
		$path = $wp_textdomain_registry->get( $domain, $locale );
	}

	if ( $path ) {
		$path = untrailingslashit( $path );
	}

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

	$relative       = false;
	$languages_path = WP_LANG_DIR;

	$src_url = wp_parse_url( $src );
	if ( ! $src_url ) {
		return load_script_translations( false, $handle, $domain );
	}
	$src_url['path'] ??= '';

	$content_url = wp_parse_url( content_url() );
	if ( ! $content_url ) {
		return load_script_translations( false, $handle, $domain );
	}

	$plugins_url = wp_parse_url( plugins_url() );
	$site_url    = wp_parse_url( site_url() );
	$theme_root  = get_theme_root();

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

		/*
		 * Ensure correct languages path when using a custom `WP_PLUGIN_DIR` / `WP_PLUGIN_URL` configuration,
		 * a custom theme root, and/or using Multisite with subdirectories.
		 * See https://core.trac.wordpress.org/ticket/60891 and https://core.trac.wordpress.org/ticket/62016.
		 */

		$theme_dir = array_slice( explode( '/', $theme_root ), -1 );
		$dirname   = $theme_dir[0] === $relative[0] ? 'themes' : 'plugins';

		$languages_path = WP_LANG_DIR . '/' . $dirname;

		$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
	 * @since 7.0.0 The `$is_module` parameter was added.
	 *
	 * @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.
	 * @param bool         $is_module Whether the source belongs to a script module (true) or a classic script (false).
	 */
	$relative = apply_filters( 'load_script_textdomain_relative_path', $relative, $src, $is_module );

	// If the source is not from WP.
	if ( ! is_string( $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 );
}
```

## История изменений

- 7.0.0 — Introduced.

## Связанные

Использует: `WP_Textdomain_Registry::get`, [`load_script_translations`](https://chugunov.pro/api-wordpress/functions/load_script_translations/), [`determine_locale`](https://chugunov.pro/api-wordpress/functions/determine_locale/), [`wp_parse_url`](https://chugunov.pro/api-wordpress/functions/wp_parse_url/), [`get_theme_root`](https://chugunov.pro/api-wordpress/functions/get_theme_root/), [`untrailingslashit`](https://chugunov.pro/api-wordpress/functions/untrailingslashit/), [`content_url`](https://chugunov.pro/api-wordpress/functions/content_url/), [`plugins_url`](https://chugunov.pro/api-wordpress/functions/plugins_url/), [`site_url`](https://chugunov.pro/api-wordpress/functions/site_url/), [`trailingslashit`](https://chugunov.pro/api-wordpress/functions/trailingslashit/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`load_script_module_textdomain`](https://chugunov.pro/api-wordpress/functions/load_script_module_textdomain/), [`load_script_textdomain`](https://chugunov.pro/api-wordpress/functions/load_script_textdomain/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/_load_script_textdomain_from_src/
