0
votes

AIM:

I'd like to translate certain words in the parent theme in the translation files that are protected from updates to the parent theme.

APPROACH:

I have saved a .po and .mo file in wp-content/themes/child-theme-name/languages/ that has the translated words.

I have amended the child functions.php with the following:

function my_child_theme_locale() {
    load_child_theme_textdomain( 'total', get_stylesheet_directory() . '/languages' );
    
}
add_action( 'after_setup_theme', 'my_child_theme_locale' , 42 );

I also tried this:

add_action("after_setup_theme", function () {

    load_theme_textdomain( 'rookie', get_stylesheet_directory() . '/languages' );

}, 5);

Neither had any impact! the translations only show when I save the .mo and .po file in the folder wp-content/languages/themes but here they are not save from updates, so it's not viable.

Could someone help me how to get the translation files to work in a update-save manner?

Thanks a lot!

1

1 Answers

0
votes

Instead, it is best to upload your translation files directly to your child theme /languages folder. Follow the steps below.

  1. Use Poedit (or similar tool) to create translation files.

Find the needed .pot file in the /languages directory, which is located in the root of the parent theme folder. Use that .pot file in a translation tool like Poedit to create your .po and .mo translation files.

  1. Edit child theme functions.php file.

Depending on your child theme, you may or may not have a functions.php file. If you do not, create it in the root of your child theme.

Add the following code to the functions.php file:

function child_theme_slug_setup() {
    load_child_theme_textdomain( 'parent-theme-slug', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'child_theme_slug_setup' );
  1. Add your translation files.

Upload your .po and .mo files to the /wp-content/themes/child-theme/languages directory. If you do not have a /languages folder in your child theme, create it. The file names should follow this format: es_ES.po & es_ES.mo (example for Spanish translation). Your file names should not include the theme slug.

Your file names will use the text domain of the parent theme you are translating. So if you are translating Vendd to Spanish, your file paths would be /wp-content/themes/child-theme/languages/es_ES.po and /wp-content/themes/child-theme/languages/es_ES.mo.