Codex

Function Reference/load theme textdomain

Contents

Description

Loads the theme's translated strings.

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, sv_SE.mo for example.

Usage

<?php load_theme_textdomain$domain$path ?>

Parameters

$domain
(string) (required) Unique identifier for retrieving translated strings.
Default: None
$path
(unknown) (optional)
Default: false

Return Values

(void) 
This function does not return a value.

Examples

1st example

The load_theme_setup() function should generally be called from within the after_setup_theme action hook.

add_action('after_setup_theme', 'my_theme_setup');
function my_theme_setup(){
    load_theme_textdomain('my_theme', get_template_directory() . '/languages');
}

The .mo files must use language-only filenames, like languages/de_DE.mo in your theme directory.

Unlike plugin language files, a name like my_theme-de_DE.mo will NOT work. Although plugin language files allow you to specify the text-domain in the filename, this will NOT work with themes. Language files for themes should include the language shortcut ONLY.

2nd example

you can use this example if you wish to switch theme language using a variable passed within the URL, for example to load the Tamazikht language, your URL would look like; www.example.com/?l=tmz, this will search for a .mo file with name tmz.mo in the language directory inside your theme.

// CHANGE LOCAL LANGUAGE
	// must be called before load_theme_textdomain()
	add_filter( 'locale', 'my_theme_localized' );
	function my_theme_localized($locale) {
		if (isset($_GET['l'])) {
			return $_GET['l'];
		}
		return $locale;
	}
// SET THEME LANGUAGES DIRECTORY
	// Theme translations can be filed in the my_theme/languages/ directory
	// Wordpress translations can be filed in the wp-content/languages/ directory
	load_theme_textdomain( 'my_theme', TEMPLATEPATH . '/languages' );

Notes

  • l10n is an abbreviation for localization.

Change Log

Since: 1.5.0

Source File

load_theme_textdomain() is located in wp-includes/l10n.php.

Related

Localization: get_locale(), load_default_textdomain(), load_plugin_textdomain(), load_textdomain(), load_theme_textdomain()

See also index of Function Reference and index of Template Tags.