1

What I'm doing

I am translating a child theme and followed the instructions on https://developer.wordpress.org/themes/advanced-topics/child-themes/#internationalization.

What I did so far

Step 0

All the text strings in my php files follow the structure of

_e('this string needs translation', 'my_text_domain')

Also there are currently no php files from the parent theme in my child theme's folder. I just mention that in case someone thinks that this could be the problem:

In the event that a template file from the parent them has been included, the textdomain should be changed from the one defined in the parent theme to the one defined by the child theme.

Step 1

I created a "/lang/" folder in my child theme folder

Step 2

I used poedit in order to create a new wp theme translation, so de_DE.mo as well as de_DE.po files were created and saved to my child themes lang folder.

Step 3

I have included in my child themes functions.php:

add_action('after_setup_theme', 'my_lang_setup');
function my_lang_setup()
{
    $lang = get_stylesheet_directory() . '/lang';
    load_child_theme_textdomain('my_text_domain', $lang);
}

Result of Step 0 - 3

All the strings of my child theme ARE translated and show up correctly in my front end!

The issues I am trying to solve

  1. All the strings of the parent theme aren't translated anymore and just show up in english
  2. When updating (or loading) the translations in poedit it removes all the strings from the parent theme (which might be the major issue)

Questions

  1. Of course, how to solve my issues?
  2. Does the child theme's text domain have to be the same as the parent theme's text domain? I found different statements / "How to's" so I am a bit confused.
  3. Is there anything I am missing?
  4. There are four options in order to translate with poedit:
    • Edit translation
    • Create new translation
    • Translate Wordpress theme or plugin
    • Translate together with others (not relevant)

I tried I guess all of the above mentioned options with the same result. Is there a way to include the parent themes language files / catalogue?

1
  • 5. Does the child themes po/mo files have to include the parent theme's strings?
    – wbq
    Commented Apr 17, 2019 at 12:09

2 Answers 2

1

Found a solution that works for me:

add_action( 'after_setup_theme', 'avia_lang_setup' );
function avia_lang_setup() {
    $lang = apply_filters('parent-theme-slug', get_template_directory()  . '/lang');
    load_theme_textdomain('avia_framework', $lang);
    load_child_theme_textdomain( 'child-theme-text-domain', get_stylesheet_directory() . '/lang' );
}

Note: Exchange "parent-theme-slug" (typically the parent theme name in small letters) and "child-theme-text-domain" (child theme text domain of your choice)

0

Does the child theme's text domain have to be the same as the parent theme's text domain?

It must NOT be the same.

Text domains must be unique. If the parent theme loads a file into "my_text_domain" and then your child theme loads a file into "my_text_domain", it will overwrite the previous one.

2
  • Thanks for your answer! That's actually how I set it up, but still have the same issue with the parent theme strings. Any ideas?
    – wbq
    Commented Apr 18, 2019 at 12:05
  • From what you've posted, no. I suggest you post real details that can be verified/reproduced by people attempting to answer your question.
    – Tim
    Commented Apr 23, 2019 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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