0

I am building a website with WordPress and I am using the Generatepress theme. However:

  • I need to add functions, so I created a child theme.
  • Generatepress is not available in a language I need (Slovak), so I have to translate it myself.

I took an existing language file, modified it with Poedit and put sk_SK.mo into a languages directory of my child theme directory. It didn't work, so after googling, I added this to the child theme's functions.php file:

function generatepress_extended_locale() {
    load_child_theme_textdomain( 'generatepress', get_stylesheet_directory() . '/languages' );
}
add_action( 'after_setup_theme', 'generatepress_extended_locale' );

However, my website still appears in English.

Interestingly, if I replace the text domain with something else and use the same text domain in a template of my child theme, it works, which means that my .mo file and its location are fine. But I would like to translate the strings of the parent them and I really don't know why it doesn't work. So I would be really glad if someone could help me.


Okay, I kinda found a solution (it's probably dirty but it works). I copied the entire generate_setup() function (the one that uses load_theme_textdomain()) from the parent theme's functions.php into the to the child theme's functions.php and added this line:

load_child_theme_textdomain( 'generatepress', get_stylesheet_directory() . '/languages' );

I guess the problem comes from the fact that load_theme_textdomain() was originally called after load_child_theme_textdomain() with the same text domain and somehow overrided it.

  • in your theme's functions.php file add this add_action('init',function(){ echo get_locale(); exit; }); it should be sk_SK to translate strings to Slovak . – Govind Kumar Nov 30 '16 at 10:22
  • It displays sk_SK. – Mutre Nov 30 '16 at 10:24
  • what is language's .mo and .po file name in your language folder ? try to rename generatepress-sk_SK.mo and generatepress-sk_SK.po – Govind Kumar Nov 30 '16 at 10:26
  • They are named sk_SK.po and sk_SK.mo. I renamed them as you said but it doesn't work. – Mutre Nov 30 '16 at 10:46
  • Ok, where did you added this code in child or parent theme? which is in your question ? – Govind Kumar Nov 30 '16 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.