is_textdomain_loaded( string $domain ): bool

Determines whether there are translations for the text domain.


Text domain. Unique identifier for retrieving translated strings.


bool Whether there are translations.


function is_textdomain_loaded( $domain ) {
	global $l10n;
	return isset( $l10n[ $domain ] ) && ! $l10n[ $domain ] instanceof NOOP_Translations;



User Contributed Notes

  1. Skip to note 2 content

    There are situations where one requires a plugin translation locale to be loaded which is different from the current user locale.

    For example, in multilingual websites, creating a translation of a post/widget requires some translations to be loaded for a given plugin text domain. The user locale (dashboard locale) is loaded by default, so it is important to unload that if it has been loaded already and seek the translation file to load for the text domain for the requested locale,

    if ( is_textdomain_loaded( $plugin ) ) {
    	unload_textdomain( $plugin );
    $mofile = sprintf( '', $plugin, $locale );
    //check the installation language path first.
    $domain_path = path_join( WP_LANG_DIR, 'plugins' );
    load_textdomain( $plugin, path_join( $domain_path, $mofile ) );
    if ( ! $loaded ) { //else, check the plugin language folder.
    	$domain_path = path_join( WP_PLUGIN_DIR, "{$plugin}/languages" );
    	$loaded = load_textdomain( $plugin, path_join( $domain_path, $mofile ) );

You must log in before being able to contribute a note or feedback.