WP_Translation_Controller::locate_translation( string $singular, string $textdomain = ‘default’, string $locale = null ): array{source:

In this article

Locates translation for a given string and text domain.

Parameters

$singularstringrequired
Singular translation.
$textdomainstringoptional
Text domain. Default 'default'.

Default:'default'

$localestringoptional
Locale. Default current locale.

Default:null

Return

array{source: WP_Translation_File, entries: string[]}|false { Translations on success, false otherwise.
@type WP_Translation_File $source Translation file instance.
@type string[] $entries Array of translation entries.
}

Source

protected function locate_translation( string $singular, string $textdomain = 'default', ?string $locale = null ) {
	if ( array() === $this->loaded_translations ) {
		return false;
	}

	// Find the translation in all loaded files for this text domain.
	foreach ( $this->get_files( $textdomain, $locale ) as $moe ) {
		$translation = $moe->translate( $singular );
		if ( false !== $translation ) {
			return array(
				'entries' => explode( "\0", $translation ),
				'source'  => $moe,
			);
		}
		if ( null !== $moe->error() ) {
			// Unload this file, something is wrong.
			$this->unload_file( $moe, $textdomain, $locale );
		}
	}

	// Nothing could be found.
	return false;
}

Changelog

VersionDescription
6.5.0Introduced.

User Contributed Notes

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