I'm trying to add translations to my theme. I went through the documentation and many questions here on Wordpress Development Stack.
Setted a text domain in my style.css
file:
/*
Theme Name: My Theme
Text Domain: my-theme
*/
Loaded the text domain in my functions.php
file:
add_action( 'after_setup_theme', 'my_theme_load_theme_textdomain' );
function my_theme_load_theme_textdomain() {
load_theme_textdomain( 'my-theme' );
}
Also tried passing a 2nd argument to load_theme_textdomain()
:
load_theme_textdomain( 'my-theme', get_template_directory() . '/languages' );
Added _e( 'Featured', 'my-theme' )
in my index.php
file. Also tried without the 2nd argument _e( 'Featured' )
.
Added both es.mo
and es.po
files into a languages
folder in my theme root directory.
languages\es.mo
languages\es.po
Also tried naming them with the text domain as a prefix: my-theme-es.mo
and my-theme-es.mo
.
The content of es.po
is as follow:
msgid "Featured"
msgstr "Destacados"
The es.mo
file was generated using Poedit free version. Also tried with po2mo.net.
I setted the language to spanish in the General Settings page. Also tried adding define( 'WPLANG', 'es' )
to my wp-config.php
file.
But everytime I get "Featured" instead of "Destacados" when the page is rendered.
I'm using WordPress 5.3 on Windows (XAMPP). I checked with phpinfo()
that GetText support is enabled.
Any clues?
Thanks for your time.
_e( 'Featured', ' my-theme' )
with a space before "my-theme", is it a typo ?echo __('Featured', 'gurim')
, which uses the real name of the theme.es_ES
. try with filenameses_ES.po
andes_ES.mo
es_ES
but just tried that and same result. Also removeddefine( 'WPLANG', 'es' )
from the config file.wp-content/languages/themes/my-theme-es_ES.mo
.