On this page
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
$domainstring Required-
Text domain.
$localestring Required-
Locale.
Return
string|false Language directory path or false if there is none available.
Source
File: wp-includes/class-wp-textdomain-registry.php. View all references
private function get_path_from_lang_dir( $domain, $locale ) {
$locations = array(
WP_LANG_DIR . '/plugins',
WP_LANG_DIR . '/themes',
);
if ( isset( $this->custom_paths[ $domain ] ) ) {
$locations[] = $this->custom_paths[ $domain ];
}
$mofile = "$domain-$locale.mo";
foreach ( $locations as $location ) {
if ( ! isset( $this->cached_mo_files[ $location ] ) ) {
$this->set_cached_mo_files( $location );
}
$path = $location . '/' . $mofile;
if ( in_array( $path, $this->cached_mo_files[ $location ], true ) ) {
$this->set( $domain, $locale, $location );
return trailingslashit( $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 ] ) ) {
$path = trailingslashit( $this->custom_paths[ $domain ] );
$this->set( $domain, $locale, $path );
return $path;
}
$this->set( $domain, $locale, false );
return false;
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Textdomain_Registry::set_cached_mo_files() wp-includes/class-wp-textdomain-registry.php | Reads and caches all available MO files from a given directory. |
| WP_Textdomain_Registry::set() wp-includes/class-wp-textdomain-registry.php | Sets the language directory path for a specific domain and locale. |
| trailingslashit() wp-includes/formatting.php | Appends a trailing slash. |
Used By
| Used By | Description |
|---|---|
| WP_Textdomain_Registry::get() wp-includes/class-wp-textdomain-registry.php | Returns the languages directory path for a specific domain and locale. |
Changelog
| Version | Description |
|---|---|
| 6.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_textdomain_registry/get_path_from_lang_dir