WP_Translation_Controller::load_file( string $translation_file, string $textdomain = ‘default’, string $locale = null ): bool

In this article

Loads a translation file for a given text domain.

Parameters

$translation_filestringrequired
Translation file.
$textdomainstringoptional
Text domain. Default 'default'.

Default:'default'

$localestringoptional
Locale. Default current locale.

Default:null

Return

bool True on success, false otherwise.

Source

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

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.