Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #642149

    efficaces
    Participant

    Hi,

    I’ve encountered the following fatal error :

    Fatal error: Cannot redeclare translate_search_string() (previously declared in /home/content/p3pnexwpnas02_data02/31/2723131/html/wp-content/themes/x-child/functions.php:28) in /home/content/p3pnexwpnas02_data02/31/2723131/html/wp-content/themes/x-child/functions.php on line 38

    Can you please help?

    Thanks,

    Julie

    #642190

    Prasant Rai
    Moderator

    Hello Julie,

    Thanks for writing in!

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    Thanks.

    #642300

    efficaces
    Participant
    This reply has been marked as private.
    #642515

    Lely
    Moderator

    Hello Julie,

    It would be best if we can see the content of your functions.php file. Based on the error you have multiple declaration of this function translate_search_string(). Can you also give us a copy of the code you’ve added so we can check it on our setup?

    You can always ask to revert them to a previous working version.

    #642540

    efficaces
    Participant
    This reply has been marked as private.
    #642697

    Lely
    Moderator

    Hello There,

    Thank you for giving us the code.
    Please update the code to this:

    add_filter( 'gettext', 'translate_search_string', 20, 3 );
    
    function translate_search_string( $translated_text, $text, $domain ) {
    if ( $text == 'Read More' ) return __( 'Lire la suite', $domain );
    else if ( $text == 'Leave a comment' ) return __( 'Ajouter un commentaire', $domain );
    else return $translated_text;
    }
    

    Hope this helps.

    #643250

    efficaces
    Participant

    Hello. Thank you for providing the code. I was able to fix the problem with my hosting provider. However, the code to translate Leave a Comment on posts doesn’t work. Should I be adding the code to a different php file? thanks!

    #643495

    Thai
    Moderator

    Hi There,

    Please update the previous code a bit:

    add_filter( 'gettext', 'translate_search_string', 20, 3 );
    
    function translate_search_string( $translated_text, $text, $domain ) {
    if ( $text == 'Read More' ) return __( 'Lire la suite', $domain );
    else if ( $text == 'Leave a Comment' ) return __( 'Ajouter un commentaire', $domain );
    else return $translated_text;
    }

    The English text is Leave a Comment, not Leave a comment.

    Hope it helps 🙂

    #646288

    efficaces
    Participant

    Awesome, it works! If there are other text entries I’d like to translate, should I do it like this:

    function translate_search_string( $translated_text, $text, $domain ) {
    if ( $text == ‘Read More’ ) return __( ‘Lire la suite’, $domain );
    else if ( $text == ‘Leave a Comment’ ) return __( ‘Ajouter un commentaire’, $domain );
    else if ( $text == ‘Submit’ ) return __( ‘Envoyer’, $domain );
    else return $translated_text;
    }

    Also, how can I translate the tooltips when hovering on an link?

    #646467

    efficaces
    Participant
    This reply has been marked as private.
    #646570

    Zeshan
    Member

    Hi there,

    Thanks for writing in!

    You need to use fr_FR as it’s selected in your site (see: http://prntscr.com/8x55am).

    In regard to your earlier question, yes you can translate more strings using else if conditional.

    Thank you!