Translate a child theme with pure PHP and gettext

I’m trying to translate a child theme of a parent theme that has all msgstr empty.

Therefore, I’ve created the file using the “WordPress i18n tools” recommended in the docs together with msgfmt. I put the file into my child theme directory’s subfolder languages/child.

To tell WordPress about it, I added this to my functions.php where mo_theme is the parent theme’s translation domain:

add_action( 'after_setup_theme', function () {
    load_theme_textdomain( 'mo_theme', get_stylesheet_directory() . '/languages/child' );
} );

However, the translation I’ve defined is not used. The .mo file looks OK, and other things defined in my functions.php have an effect.

I have used gettext in other contexts, but not yet together with WordPress. Is there anything special I should care about?


My parent theme defines __('View your shopping cart', 'mo_theme').

In the .po file I’ve created, this is translated like this:

#: woocommerce/woocommerce-integration.php:76
msgid "View your shopping cart"
msgstr "Zum Warenkorb"

Solutions Collecting From Web of "Translate a child theme with pure PHP and gettext"