_load_textdomain_just_in_time()WP 4.6.0

Loads plugin and theme text domains just-in-time.

When a textdomain is encountered for the first time, we try to load the translation file from wp-content/languages, removing the need to call load_plugin_textdomain() or load_theme_textdomain().

Эта функция считается внутренней для использования самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

true|false. True when the textdomain is successfully loaded, false otherwise.

Использование

_load_textdomain_just_in_time( $domain );
$domain(строка) (обязательный)
Text domain. Unique identifier for retrieving translated strings.

Заметки

  • Global. MO[]. $l10n_unloaded An array of all text domains that have been unloaded again.
  • Global. WP_Textdomain_Registry. $wp_textdomain_registry WordPress Textdomain Registry.

Список изменений

С версии 4.6.0 Введена.

Код _load_textdomain_just_in_time() WP 6.1.1

function _load_textdomain_just_in_time( $domain ) {
	/** @var WP_Textdomain_Registry $wp_textdomain_registry */
	global $l10n_unloaded, $wp_textdomain_registry;

	$l10n_unloaded = (array) $l10n_unloaded;

	// Short-circuit if domain is 'default' which is reserved for core.
	if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) {
		return false;
	}

	if ( ! $wp_textdomain_registry->has( $domain ) ) {
		return false;
	}

	$locale = determine_locale();
	$path   = $wp_textdomain_registry->get( $domain, $locale );
	if ( ! $path ) {
		return false;
	}
	// Themes with their language directory outside of WP_LANG_DIR have a different file name.
	$template_directory   = trailingslashit( get_template_directory() );
	$stylesheet_directory = trailingslashit( get_stylesheet_directory() );
	if ( str_starts_with( $path, $template_directory ) || str_starts_with( $path, $stylesheet_directory ) ) {
		$mofile = "{$path}{$locale}.mo";
	} else {
		$mofile = "{$path}{$domain}-{$locale}.mo";
	}

	return load_textdomain( $domain, $mofile, $locale );
}