Skip to:
Content
Pages
Categories
Search
Top
Bottom

Translating the custom posts activity


  • milenushka
    Participant

    @milenushka

    Hi bp forum. @shanebp gave me this code to use to display my custom posts in the activity stream

    add_filter('bp_blogs_activity_new_post_action', 'record_cpt_activity_action', 1, 3);
    function record_cpt_activity_action( $activity_action,  $post, $post_permalink ) { 
    
       if( $post->post_type == 'projects' ) {
    	$activity_action  = sprintf( __( '%1$s created a new Project, %2$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
       }
    	
       return $activity_action;
    }

    Question is translation related. Should I look for this string in the buddypress.po file or translate it directly in the functions.php? And if its the last one- are there any changes I need to make to the code?

    Thank you

    M

Viewing 3 replies - 1 through 3 (of 3 total)

  • danbp
    Moderator

    @danbp

    Hi,

    it is a custom string, you will not find it in the po file. So you can translate it directly in the function.

    '%1$s created a new Project, %2$s'

    '%1$s your translation, %2$s', where first variable is the username and the second the project name

    You could also do differently and add this custom string to your po file, but in this case, you have to take care that your translation is not overiden by the next language update.


    milenushka
    Participant

    @milenushka

    Hi @danbp, thank you. The problem is mysite is RTL and when I try to add the translation into functions.php %1$s and %2$s jump and I get a weird sequence. How would I

    add this custom string to your po file

    ?

    I am saving my plugin’s translation files in wp/languages/plugins so they are safe from updates.

    Thank you.


    danbp
    Moderator

    @danbp

    See the WP Codex to get the answer: codex.wordpress.org/Translating_WordPress

    The order of %1$s and %2$s is not important.

    If you code directly your language into the string, you can write as usual RTL and place %2$s first write something, add %1$s and write another thing…

    That said, and if you are using a RTL language like hebrew (as i suppose), you may have some special characters which are (perhaps) not recognized by gettext. And in this case you have to use unicode, in other words, HTML letters.

    The orignal created a new Project is translated to יצר פרויקט חדש
    But i don’t know much about hebrew (or persian or arabic) characters.
    Search from here how to get rid of this:
    https://codex.wordpress.org/WordPress_in_Your_Language
    or see here:
    http://www.i18nguy.com/unicode/hebrew.html

    And apologize if you use another RTL language.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Translating the custom posts activity’ is closed to new replies.
Skip to toolbar