_load_textdomain_just_in_time( string $domain ): bool
- Since
- 4.6.0
- Source
wp-includes/l10n.php:1423
Loads plugin and theme text domains just-in-time.
Description
When a textdomain is encountered for the first time, we try to load the translation file from
wp-content/languages, removing the need to call load_plugin_textdomain() or load_theme_textdomain().Parameters
$domainstring- Text domain. Unique identifier for retrieving translated strings.
Return
bool- True when the textdomain is successfully loaded, false otherwise.
Uses · 10
- determine_locale()Determines the current locale desired for the request.
- doing_action()Returns whether or not an action hook is currently being processed.
- did_action()Retrieves the number of times an action has been fired during the current request.
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- trailingslashit()Appends a trailing slash.
- get_template_directory()Retrieves template directory path for the active theme.
- get_stylesheet_directory()Retrieves stylesheet directory path for the active theme.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- load_textdomain()Loads a .mo file into the text domain $domain.
Used by · 1
- get_translations_for_domain()Returns the Translations instance for a text domain.
Source
function _load_textdomain_just_in_time( $domain ) { /** @var WP_Textdomain_Registry $wp_textdomain_registry */ global $l10n_unloaded, $wp_textdomain_registry; $l10n_unloaded = (array) $l10n_unloaded; // Short-circuit if domain is 'default' which is reserved for core. if ( 'default' === $domain || isset( $l10n_unloaded[ $domain ] ) ) { return false; } if ( ! $wp_textdomain_registry->has( $domain ) ) { return false; } $locale = determine_locale(); $path = $wp_textdomain_registry->get( $domain, $locale ); if ( ! $path ) { return false; } if ( ! doing_action( 'after_setup_theme' ) && ! did_action( 'after_setup_theme' ) ) { _doing_it_wrong( __FUNCTION__, sprintf( /* translators: 1: The text domain. 2: 'init'. */ __( 'Translation loading for the %1$s domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the %2$s action or later.' ), '<code>' . $domain . '</code>', '<code>init</code>' ), '6.7.0' ); } // Themes with their language directory outside of WP_LANG_DIR have a different file name. $template_directory = trailingslashit( get_template_directory() ); $stylesheet_directory = trailingslashit( get_stylesheet_directory() ); if ( str_starts_with( $path, $template_directory ) || str_starts_with( $path, $stylesheet_directory ) ) { $mofile = "{$path}{$locale}.mo"; } else { $mofile = "{$path}{$domain}-{$locale}.mo"; } return load_textdomain( $domain, $mofile, $locale );}History
Introduced in 4.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/l10n.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.