Skip to:
Content
Pages
Categories
Search
Top
Bottom

Help with labels


  • shemakeswebsites
    Participant

    @shemakeswebsites

    Hello! I have changed the label and slug from Groups to Packs successfully in most instances but I can’t figure out how to change the label found on the “Activity” tab (/members/username/activity/groups). The slug is reading as I wish (members/username/activity/packs) but the label still reads Groups.

    Can someone help? Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @shemakeswebsites,

    12.0.0 brings URL slugs customization, that’s a big improvement to have meaningful URLs for non English communities.

    These communities are using different words for things like Activity, groups etc.. They can do so thanks to the l10n feature of WordPress. So a good way to reach your goal is to use a custom translation file. And I believe it’s the best way to do so, because the page title or labels won’t be enough to really reword all places where we use groups.

    You can try to put your custom translation file into wp-content/languages/buddypress/buddypress-xx_XX.mo replacing the xx_XX with your locale maybe it’s even working with en_US.


    shemakeswebsites
    Participant

    @shemakeswebsites

    Thank you for the suggestion. I really dislike working with language files and was hoping to find a php snippet for quick fix.

    Any help would be appreciated.


    Varun Dubey
    Participant

    @vapvarun

    You can use the WordPress gettext filter.

    This filter allows you to intercept and modify text before it’s displayed on the page. Here’s an example of how you can use it to change a specific string in BuddyPress:

    /**
     * Translates specific strings in BuddyPress to new values.
     * This function hooks into the 'gettext' filter provided by WordPress, allowing for the modification
     * of text before it is displayed or used on the site. It specifically targets text within the 'buddypress' domain,
     * making it suitable for customizing or translating BuddyPress strings without altering language files.
     *
     * @param string $translated_text The text after being translated.
     * @param string $text The text before being translated.
     * @param string $domain The domain of the text being translated. This function specifically targets 'buddypress'.
     * @return string The modified or translated text.
     */
    add_filter( 'gettext', 'wbcom_translate_buddypress_strings', 20, 3 );
    
    function wbcom_translate_buddypress_strings( $translated_text, $text, $domain ) {
        // Target only BuddyPress strings to avoid affecting other texts.
        if ( 'buddypress' === $domain ) {
            switch ( $translated_text ) {
                // Example: Translate "Friends" to "Connections".
                case 'Friends':
                    $translated_text = 'Connections';
                    break;
    
                // Add more strings to translate as needed, following the pattern above.
            }
        }
    
        return $translated_text;
    }

    Inside the switch statement, you can add cases for each specific string you wish to translate or modify. Replace ‘Friends’ with the BuddyPress string you want to change, and ‘Connections’ with the desired new text.


    shemakeswebsites
    Participant

    @shemakeswebsites

    HI Varun,

    Thank you for your response but it didn’t work. 🙁

    This is what I tried to use:

    /**
     * Translates specific strings in BuddyPress to new values.
     * This function hooks into the 'gettext' filter provided by WordPress, allowing for the modification
     * of text before it is displayed or used on the site. It specifically targets text within the 'buddypress' domain,
     * making it suitable for customizing or translating BuddyPress strings without altering language files.
     *
     * @param string $translated_text The text after being translated.
     * @param string $text The text before being translated.
     * @param string $domain The domain of the text being translated. This function specifically targets 'buddypress'.
     * @return string The modified or translated text.
     */
    add_filter( 'gettext', 'wbcom_translate_buddypress_strings', 20, 3 );
    
    function wbcom_translate_buddypress_strings( $translated_text, $text, $domain ) {
        // Target only BuddyPress strings to avoid affecting other texts.
        if ( 'buddypress' === $domain ) {
            switch ( $translated_text ) {
                // Example: Translate "Friends" to "Connections".
                case 'Groups':
                    $translated_text = 'Packs';
                    break;
    
                // Add more strings to translate as needed, following the pattern above.
            }
        }
    
        return $translated_text;
    }

    thinlizzie
    Participant

    @thinlizzie

    Hi Varun

    The code snippet does not work for me.
    The Friends label does not change, neither in the Friends component nor in the Buddypress user account menu (top right on screen)
    Snippet added with Code Snippets plugin.

    Could you advise please?


    Varun Dubey
    Participant

    @vapvarun

    Code Snippet is for labels, not for main components; you can change component names from BuddyPress URL options

    @thinlizzie

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar