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
$domain
stringrequired- Text domain.
$locale
stringrequired- Locale.
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
Version | Description |
---|---|
6.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.