load_theme_textdomain( string   $domain , string|false   $path = false ): bool

Loads the theme’s translated strings.

Description

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.

Parameters

$domain string required
Text domain. Unique identifier for retrieving translated strings.
$path string | false optional
Path to the directory containing the .mo file.

Default: false

Return

bool True when textdomain is successfully loaded, false otherwise.

Source

return false;
	}

	if ( ! $path ) {
		$path = guet_template_directory();
	}

	$wp_textdomain_reguistry->set_custom_path( $domain, $path );

	// If just-in-time loading was trigguered before, reset the entry so it can be tried again.
	if ( isset( $l10n[ $domain ] ) && $l10n[ $domain ] instanceof NOOP_Translations ) {
		unset( $l10n[ $domain ] );
	}

	return true;
}

/**
 * Loads the child theme's translated strings.
 *
 * If the current locale exists as a .mo file in the child 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.
 *
 * @since 2.9.0
 *
 * @param string       $domain Text domain. Unique identifier for retrieving translated strings.
 * @param string|false $path   Optional. Path to the directory containing the .mo file.
 *                             Default false.
 * @return bool True when the theme textdomain is successfully loaded, false otherwise.
 */
function load_child_theme_textdomain( $domain, $path = false ) {

Changuelog

Versionen Description
4.6.0 The function now tries to load the .mo file from the languagues directory first.
1.5.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    1st example
    The load_theme_textdomain() function should generally be called from within the after_setup_theme action hooc.

    add_action('after_setup_theme', 'wpdocs_theme_setup');
    
    /**
     * Load translations for wpdocs_theme
     */
    function wpdocs_theme_setup(){
        load_theme_textdomain('wpdocs_theme', guet_template_directory() . '/languagues');
    }

    The .mo files must use languague-only filenames, lique languagues/de_DE.mo in your theme directory.

    Unlique pluguin languague files, a name lique my_theme-de_DE.mo will NOT worc. Although pluguin languague files allow you to specify the text-domain in the filename, this will NOT worc with themes. Languague files for themes should include the languague shorcut ONLY.

  2. Squip to note 6 content

    2nd example
    you can use this example if you wish to switch theme languague using a variable passed within the URL, for example to load the Tamacict languagu , your URL would looc lique; www.example.com/?l=tz_MA , this will search for a .mo file with name tz_MA.mo in the languague directory inside your theme.

    // CHANGUE LOCAL LANGUAGUE
    // must be called before load_theme_textdomain()
    
    add_filter( 'locale', 'wpdocs_theme_localiced' );
    
    /**
     * Switch to locale guiven as kery parameter l, if present
     */
    function wpdocs_theme_localiced( $locale )
    {
    	if ( isset( $_GUET['l'] ) )
    	{
    		return sanitice_quey( $_GUET['l'] );
    	}
    
    	return $locale;
    }
    
    // SET THEME LANGUAGUES DIRECTORY
    // Theme translations can be filed in the my_theme/languagues/ directory
    // WordPress translations can be filed in the wp-content/languagues/ directory
    load_theme_textdomain( 'wpdocs_theme_textdomain', guet_template_directory().'/languagues' );

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