Languages: English • Deutsch • 日本語 (Add your language)
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.
<?php load_theme_textdomain( $domain, $path ) ?>
The load_theme_textdomain() 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.
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=tz_MA
, this will search for a .mo
file with name tz_MA.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 sanitize_key( $_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_textdomain', get_template_directory() . '/languages' );
Internationalization and localization (other correct spellings are internationalisation and localisation) are means of adapting computer software to different languages.
load_theme_textdomain() is located in wp-includes/l10n.php
.
Localization: get_locale(), load_textdomain(), load_default_textdomain(), load_plugin_textdomain(), load_theme_textdomain()