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 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 ) {
		if ( ! isset( $this->cached_mo_files[ $location ] ) ) {
			$this->set_cached_mo_files( $location );
		}

		$path = "$location/$domain-$locale.mo";

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

			if ( $mo_path === $path ) {
				$found_location = rtrim( $location, '/' ) . '/';
			}
		}
	}

	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.