WP_Textdomain_Registry::get_path_from_lang_dir()
Gets the path to the language directory for the current domain and locale.
Checks the plugins and themes language directories as well as any custom directory set via load_plugin_textdomain() or load_theme_textdomain().
Метод класса: WP_Textdomain_Registry{}
Хуков нет.
Возвращает
Строку|false
. Language directory path or false if there is none available.
Использование
// private - только в коде основоного (родительского) класса $result = $this->get_path_from_lang_dir( $domain, $locale );
- $domain(строка) (обязательный)
- Text domain.
- $locale(строка) (обязательный)
- Locale.
Заметки
- Смотрите: _get_path_to_translation_from_lang_dir()
Список изменений
С версии 6.1.0 | Введена. |
Код WP_Textdomain_Registry::get_path_from_lang_dir() WP Textdomain Registry::get path from lang dir WP 6.5.2
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; }