I've looked through all the similar threads I can find, and I think I should have all the pieces in place to have translated strings appear, but they are not. I'm about ready to pull out my hair!

Here's what I've got going - I'm making a custom theme (based on the _s starter), and I have added templates for some custom post types (created in my own plugins). I installed the Loco Translate plugin to create and edit po/mo files. The files are stored in 'mytheme/languages'.

In my theme's functions.php I have:

 * Load theme text domain for translations
function mytheme_load_theme_textdomain() {

    if (load_theme_textdomain('mytheme', get_template_directory() . '/languages')) {
        error_log("Text Domain loaded.");
add_action('after_setup_theme', 'mytheme_load_theme_textdomain');

In my template part file, I have the strings set up for display like this:

<?php _e('My String Text', 'mytheme'); ?>

When I load the page that should have the translated strings, then look at the debug.log file, I see the message "Text Domain loaded." So that part should be working. Loco Translate correctly sees the strings and allows me to translate them. So everything in the .mo file should be correct.

I have tried hardcoding the locale in wp-config.php (just to check) by adding define('WPLANG', 'es_ES'); and echoing the global $locale variable to the debug log from within the function described above. That works correctly.

Edit: adding output from debug-mo-translations plugin

Debug MO Translations (Version 1.0)

Locale: es_ES

Domain:    mytheme
File:      /wp-content/languages/themes/mytheme-es_ES.mo (not found)
Called in: /wp-includes/l10n.php line 792 load_textdomain

Domain:    mytheme
File:      /wp-content/languages/loco/themes/mytheme-es_ES.mo (not found)
Called in: /wp-content/plugins/loco-translate/src/hooks/LoadHelper.php line 103 load_textdomain

Domain:    mytheme
File:      /wp-content/themes/mytheme/languages/es_ES.mo (0.62kb)
Called in: /wp-includes/l10n.php line 800 load_textdomain

So, I've got translatable strings in my template file, I've got translations in .po/.mo files within my theme, the locale is correctly set, and I load my theme text domain in my functions.php file. But the strings still do not appear in translated form on the front end! What am I missing?

Thanks in advance!


You should analyze the path of the language file, is it correct?

Helpful plugins for this job:

You should check the function to get the path. The function get_template_directory get the path to the parent theme, not a child theme. If you will use your translation file of an child theme, then use get_stylesheet_directory_uri. That function get always the path of the active stylesheet.

  • Hi. Thanks for the response. The .mo appears to be found. I installed the debug-mo-translations plugin. However, the translated strings are still not appearing. – eljefejb Jan 3 '18 at 17:58
  • I edited my question to include the output with formatting. – eljefejb Jan 3 '18 at 18:04
  • I read your edits. The files are loaded right. Have you active a user language? – bueltge Jan 4 '18 at 14:34
  • 1
    I got it working by refreshing my .pot file, then the .po and .mo files. Thanks for following up, though! – eljefejb Jan 4 '18 at 19:14

Well, I seem to have it sorted now. In my case, I went back and refreshed the .pot template file by making a small change and saving (using Loco Translate). Then I went back to the .po file editor screen, re-synced with the .pot file, and saved to update the .mo file. The translations are now appearing in my theme. Woo hoo!

I hope this might help the next person to run into a similar situation!

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.