WP_Translation_Controller::load_file()publicWP 6.5.0

Loads a translation file for a given text domain.

Метод класса: WP_Translation_Controller{}

Хуков нет.

Возвращает

true|false. True on success, false otherwise.

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

$WP_Translation_Controller = new WP_Translation_Controller();
$WP_Translation_Controller->load_file( $translation_file, $textdomain, ?string $locale ): bool;
$translation_file(строка) (обязательный)
Translation file.
$textdomain(строка)
Text domain.
По умолчанию: 'default'
?string $locale **
-
По умолчанию: null

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

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

Код WP_Translation_Controller::load_file() WP 6.6.2

public function load_file( string $translation_file, string $textdomain = 'default', ?string $locale = null ): bool {
	if ( null === $locale ) {
		$locale = $this->current_locale;
	}

	$translation_file = realpath( $translation_file );

	if ( false === $translation_file ) {
		return false;
	}

	if (
		isset( $this->loaded_files[ $translation_file ][ $locale ][ $textdomain ] ) &&
		false !== $this->loaded_files[ $translation_file ][ $locale ][ $textdomain ]
	) {
		return null === $this->loaded_files[ $translation_file ][ $locale ][ $textdomain ]->error();
	}

	if (
		isset( $this->loaded_files[ $translation_file ][ $locale ] ) &&
		array() !== $this->loaded_files[ $translation_file ][ $locale ]
	) {
		$moe = reset( $this->loaded_files[ $translation_file ][ $locale ] );
	} else {
		$moe = WP_Translation_File::create( $translation_file );
		if ( false === $moe || null !== $moe->error() ) {
			$moe = false;
		}
	}

	$this->loaded_files[ $translation_file ][ $locale ][ $textdomain ] = $moe;

	if ( ! $moe instanceof WP_Translation_File ) {
		return false;
	}

	if ( ! isset( $this->loaded_translations[ $locale ][ $textdomain ] ) ) {
		$this->loaded_translations[ $locale ][ $textdomain ] = array();
	}

	$this->loaded_translations[ $locale ][ $textdomain ][] = $moe;

	return true;
}