WP_Textdomain_Registry::get_path_from_lang_dir( string $domain, string $locale ): string|false

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness. Use _get_path_to_translation_from_lang_dir() instead.

Gets the path to the language directory for the current domain and locale.

Description

Checks the plugins and themes language directories as well as any custom directory set via load_plugin_textdomain() or load_theme_textdomain().

See also

Parameters

$domainstringrequired
Text domain.
$localestringrequired
Locale.

Return

string|false Language directory path or false if there is none available.

Source

private function get_path_from_lang_dir( $domain, $locale ) {
	$locations = $this->get_paths_for_domain( $domain );

	$found_location = false;

	foreach ( $locations as $location ) {
		$files = $this->get_language_files_from_path( $location );

		$mo_path  = "$location/$domain-$locale.mo";
		$php_path = "$location/$domain-$locale.l10n.php";

		foreach ( $files as $file_path ) {
			if (
				! in_array( $domain, $this->domains_with_translations, true ) &&
				str_starts_with( str_replace( "$location/", '', $file_path ), "$domain-" )
			) {
				$this->domains_with_translations[] = $domain;
			}

			if ( $file_path === $mo_path || $file_path === $php_path ) {
				$found_location = rtrim( $location, '/' ) . '/';
				break 2;
			}
		}
	}

	if ( $found_location ) {
		$this->set( $domain, $locale, $found_location );

		return $found_location;
	}

	/*
	 * If no path is found for the given locale and a custom path has been set
	 * using load_plugin_textdomain/load_theme_textdomain, use that one.
	 */
	if ( 'en_US' !== $locale && isset( $this->custom_paths[ $domain ] ) ) {
		$fallback_location = rtrim( $this->custom_paths[ $domain ], '/' ) . '/';
		$this->set( $domain, $locale, $fallback_location );
		return $fallback_location;
	}

	$this->set( $domain, $locale, false );

	return false;
}

Changelog

VersionDescription
6.1.0Introduced.

User Contributed Notes

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