• Hello there,

    Got some trouble and can’t figure out to fix despite a lot of hours spent.

    I have a function that I need to override to change the translation. I can’t just translate it through strings with WPML of course.

    function bp_nouveau_activity_state() {
    
    	$activity_id     = bp_get_activity_id();
    	$like_text       = bp_activity_get_favorite_users_string( $activity_id );
    	$comment_count   = bp_activity_get_comment_count();
    	$favorited_users = bp_activity_get_favorite_users_tooltip_string( $activity_id );
    	?>
    	<div class="activity-state <?php echo $like_text ? 'has-likes' : ''; ?> <?php echo $comment_count ? 'has-comments' : ''; ?>">
            <a href="javascript:void(0);" class="activity-state-likes">
                <span class="like-text hint--bottom hint--medium hint--multiline" data-hint="<?php echo $favorited_users; ?>"><?php echo $like_text ?: ''; ?></span>
            </a>
            <span class="ac-state-separator">&middot;</span>
    		<a href="#" class="activity-state-comments">
    			<span class="comments-count">
                    <?php if ( $comment_count > 1 ) {
                        echo $comment_count . ' ' . __( 'Comments', 'buddyboss' );
                    } else {
    	                echo $comment_count . ' ' . __( 'Comment', 'buddyboss' );
                    } ?>
                </span>
    		</a>
    	</div>
    	<?php
    }

    I want to use a hook (filter if I am not wrong) in my child theme so I can change the “Comments” and “Comment” line to something else that I can translate after that.

    Any help ? Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use the “gettext” filter to override whatever the default translation would have been. It’s applied in the translate() function:
    https://developer.www.ads-software.com/reference/functions/translate/

    Thread Starter kroenenprime

    (@kroenenprime)

    Hello @bcworkz and thank you for your answer.

    I thought and tried it, it didn’t work but I’m not sure it’s the right way, I will give you more infos.

    I’m translating the plugin with WPML and I want to keep the English language but I’m making available the French too.
    And I’ve found an issue with one word : Comment

    There are only 2 strings about it :
    Comment
    Comments

    Because in English, we can write on a button “COMMENT”, and we can write :
    – There is 1 comment
    – There are 2 comments

    But in French, it’s 3 different words to do the same and I can’t translate 3 words.

    So the trick to do it, is to edit the lines in the function so I can change them in French (and let the string register for WPML) and then use the plugin to translate them in English so I have all my words in both languages.

    I don’t know if I’ve been easy to read.

    The plugin support told me :
    It’s a template function file. In this file, functions are available. So you can use the hooks and filter to make some changes to a particular function.

    But not more help.

    Richard

    (@richardcoffee)

    This article might help you out.

    Apparently WPML is aware of the problem.

    Good Luck!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Override Plugin Function with Hooks’ is closed to new replies.