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!