• Resolved superninchen

    (@superninchen)


    Hi,

    I followed the instructions in this page: https://localise.biz/wordpress/plugin/child-themes

    But I can’t get Loco to recognise the translatable strings in my functions.php.

    Here’s what I did
    1) added the following function to my child theme’s functions.php at the top of the file

    function AIPOWERSEO_setup() {
    	load_child_theme_textdomain( 'AIPOWER', get_stylesheet_directory().'/languages' );
    }
    add_action( 'after_setup_theme', 'AIPOWER_setup' );

    Remark: When I copied and pasted the above snippet from the manual, I couldn’t save the file functions.php. In the error log I found a message warning me of a possible SQL injection. Only after removing the line “$path = get_stylesheet_directory().’/language'” and putting it directly into the signature of load_child_theme_textdomain I could get it to let me save it.

    2) in another function, further below, I marked the translatable strings like this:
    $checkout_data_label_name = __('<br/><strong>Customer Name:</strong> ', 'AIPOWER');

    3) I created a new template file for the child theme following the messages in Loco Translate in WP Admin page

    4) I created a new language file for the template, selecting Swiss German from the list.

    Now, the template only has three entries, the first three lines from the child theme’s CSS file. But not the strings I added like shown in step 2).

    What am I overlooking?

    Thank you in advance for any pointers.

    Nina

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter superninchen

    (@superninchen)

    Note: The code in bullet point 1) above is actually correct in my functions.php. I only forgot to change the function’s name before pasting it here.

    Plugin Author Tim W

    (@timwhitlock)

    The code in point 1) isn’t read by Loco Translate. It has nothing to do with extracting strings.

    The code in point 2) will be extracted as long as AIPOWER is the text domain for your child theme.

    Plugin Author Tim W

    (@timwhitlock)

    Also, what do you mean by “yet once again”?

    • This reply was modified 4 years, 6 months ago by Tim W.
    Thread Starter superninchen

    (@superninchen)

    By “yet once again” I meant that this question had been asked before a couple of times. However, none of the threads had a solution to my problem. Hence my remark.

    The code in point 1) is from the manual linked in the OP. It seemed like that would be necessary to make the strings known to Loco. You mean it isn’t needed at all in my functions.php?

    Plugin Author Tim W

    (@timwhitlock)

    The code in point 1) is you loading your translations into your theme at runtime. You need it to display your translations. It is in my guide for this reason. As I said – Loco Translate’s string extractor does not look at this code block. It does not affect string extraction at all.

    The string extractor does read the code on point 2). There is nothing wrong with your code there, providing you are using the correct text domain configured for your child theme. A very common mistake is to use the parent theme’s text domain, which my article warns against. If you’ve made some other mistake, it’s not evident in the information you’ve posted.

    Thread Starter superninchen

    (@superninchen)

    Alright, thank you so far for your time and effort. I will look into the code again tomorrow and will report back if I could find any other error.

    So far, I believe I did everything according to the manual, therefore it wouldn’t occur to me why the strings don’t show up in Loco.

    .

    Thread Starter superninchen

    (@superninchen)

    I haven’t found any error but tried everything again from scratch and now it’s working.

    Thank you very much @timwhitlock for your help!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Translating strings in functions.php (yet once again)’ is closed to new replies.