Child Theme Translations with PoEdit

admin2025-04-21  0

What I'm doing

I am translating a child theme and followed the instructions on .

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?

What I'm doing

I am translating a child theme and followed the instructions on https://developer.wordpress/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?

Share Improve this question asked Apr 17, 2019 at 11:56 wbqwbq 2513 silver badges9 bronze badges 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
Add a comment  | 

2 Answers 2

Reset to default 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)

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.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745241756a292051.html

最新回复(0)