Theme doesn't want to load localization files

Here is my functions.php excerpt:

function get_theme_text_domain()
{
    //Same behavior if I return the string as 'return 'whatever'
    $theme = wp_get_theme();
    return $theme-get('TextDomain');
}

function tamtando_theme_setup()
{
    load_textdomain(get_theme_text_domain(), get_template_directory() . '/languages');

[...]

}

add_action('after_setup_theme', 'tamtando_theme_setup');

$theme is an array with all theme's properties: as expected. $theme-get('TextDomain') returns 'tamtando': as expected.

I've noticed that the theme wasn't translating any string when using __('somestring', get_theme_text_domain()).

I've then tried to see what was going on with the debugger, while executing load_textdomain(get_theme_text_domain(), get_template_directory() . '/languages');.

Here I've realized that import_from_reader($reader), located on /wp-includes/pomo/mo.php, was returning false, because, I think, $reader-readint32() returns false. I suppose, this happens because either the file can't be found, or it has some issue.

I've checked: the file appear correct and I've even recreated it a couple of times, using different tools, but the issue is still present.

This is not the first theme I'm writing and I mostly use always the same patterns, so I'm really lost on this issue.

Anyone knows a possible reason for this behavior?

Topic textdomain l10n localization Wordpress

Category Web


One error: the function is load_theme_textdomain(), not load_textdomain(). The former is used for Themes to define/load a textdomain; the latter is for core, I believe. (Plugins have an analogous function, load_plugin_textdomain().)

Try using:

load_theme_textdomain( get_theme_text_domain(), get_template_directory() . '/languages' );

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.