0

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?

  • Where is the code failing? What is returned for $theme = wp_get_theme()? What is returned for $theme->get('TextDomain')? – Chip Bennett Jun 21 '13 at 18:10
3

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' );
  • You're right! Now it works as expected. I should have mistyped it. This is this sort of errors that only different eyes can see :) Thanks! – Andrea Sciamanna Jun 21 '13 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.