• Resolved anish6

    (@anish6)


    Hello, this is my first time asking a question here so please don’t mind if I don’t do it the correct way.

    My question:
    I want to translate custom strings in my child theme using Poedit. I have been reading a lot of questions on forums and trying a lot, but I just can’t make it work.
    Till now what I have done:

    – Add this code to my child functions.php:

    function oceanwp_child_setup() {
        $path = get_stylesheet_directory().'/languages';
        load_child_theme_textdomain( 'oceanwp', $path );
    }
    add_action( 'after_setup_theme', 'oceanwp_child_setup' );

    – Creating a /languages folder in my child theme;
    – Extracting the strings from my child theme using Poedit;
    – Translating the strings in Poedit and saving them in /languages (.po & .mo);
    ____
    This above did not work, so I tried using a different text-domain for the child theme but that also did not work.

    One of the strings I want to translate is
    esc_html__( 'Custom Menu', 'oceanwp' )

    I tried renaming the /languages folder in the main theme, copying all the files to the child theme /languages and the translation of the main theme strings were all working. I think that the main theme language is overriding the child theme.

    So now I’m really desperate and you guys are my only hope left :(.
    Any help will be much appreciated.
    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Amit Singh

    (@apprimit)

    Hello,

    Have you activated the child theme? Can you kindly share your site link so that I can check it? Also, try to update the string in the Poedit tool.

    Thread Starter anish6

    (@anish6)

    Hi Amit, thanks for replying.

    Yes I have activated the child theme.
    My website : https://www.equalitywebshop.com

    I did update the string in Poedit. When I place esc_html__( 'Custom Menu', 'oceanwp-child' ) in the parent functions.php, the translation shows up correctly in the front-end. But when I place it in the child functions.php the translation does not take place.

    Hope you can find the error ??

    Amit Singh

    (@apprimit)

    That’s odd. Can you please tell me the steps to replicate the issue?

    • This reply was modified 5 years ago by Amit Singh.
    Thread Starter anish6

    (@anish6)

    Hi Amit, I got it working with a plugin called TranslatePress. Thanks ??

    Hello,
    I had similar problem but from the other side.

    I have followed this tutorial: https://docs.oceanwp.org/article/258-add-language-files-in-child-theme

    And code from there didn’t work.

    I’ve copied anish6 code and it worked. As I am not a coder, dont know the difference. Could someone tell me?

    WORKING:

    function oceanwp_child_setup() {
        $path = get_stylesheet_directory().'/languages';
        load_child_theme_textdomain( 'oceanwp', $path );
    }
    add_action( 'after_setup_theme', 'oceanwp_child_setup' );

    NOT WORKING:

    function my_child_theme_locale() {
        load_child_theme_textdomain( 'ocean', get_stylesheet_directory() . '/languages' );
    }
    add_action( 'after_setup_theme', 'my_child_theme_locale' );
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘String translation in child theme’ is closed to new replies.