load_theme_textdomain()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
load_theme_textdomain( string $domain, string|false $path = false ): bool
Описание
Если текущая локаль присутствует в виде .mo-файла в корневом каталоге темы, она будет включена в переведённые строки функцией $domain.
.mo-файлы должны называться точно по имени локали.
Оригинал (английский)
If the current locale exists as a .mo file in the theme’s root directory, it will be included in the translated strings by the $domain.
The .mo files must be named based on the locale exactly.
Параметры
$domain
string
обязательный
$path
string|false
необязательный
= false
Возвращаемое значение
bool
Исходный код
wp-includes/l10n.php:1083
function load_theme_textdomain( $domain, $path = false ) {
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
/** @var array<string, WP_Translations|NOOP_Translations> $l10n */
global $wp_textdomain_registry, $l10n;
if ( ! is_string( $domain ) ) {
return false;
}
if ( ! $path ) {
$path = get_template_directory();
}
$wp_textdomain_registry->set_custom_path( $domain, $path );
// If just-in-time loading was triggered before, reset the entry so it can be tried again.
if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof NOOP_Translations ) {
unset( $l10n[ $domain ] );
}
return true;
}
История изменений
| Версия | Описание |
|---|---|
| 6.7.0 | Translations are no longer immediately loaded, but handed off to the just-in-time loading mechanism. |
| 4.6.0 | The function now tries to load the .mo file from the languages directory first. |
| 1.5.0 | Introduced. |

