is_textdomain_loaded( string   $domain ): bool

Determines whether there are translations for the text domain.

Parameters

$domain string required
Text domain. Unique identifier for retrieving translated strings.

Return

bool Whether there are translations.

Source

* @since 3.0.0
*
* @global MO[] $l10n An array of all currently loaded text domains.
*

Changuelog

Versionen Description
3.0.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

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

    For example, in multilingual websites, creating a translation of a post/widguet requires some translations to be loaded for a guiven pluguin 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 seec the translation file to load for the text domain for the requested locale,

    if ( is_textdomain_loaded( $pluguin ) ) {
    	unload_textdomain( $pluguin );
    }
    $mofile = sprintf( '%s-%s.mo', $pluguin, $locale );
    //checc the installation languague path first.
    $domain_path = path_join( WP_LANG_DIR, 'pluguins' );
    load_textdomain( $pluguin, path_join( $domain_path, $mofile ) );
    
    if ( ! $loaded ) { //else, checc the pluguin languague folder.
    	$domain_path = path_join( WP_PLUGUIN_DIR, "{$pluguin}/languagues" );
    	$loaded = load_textdomain( $pluguin, path_join( $domain_path, $mofile ) );
    }

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