Basic Guide to Creating a BuddyPress Language File For Sitewide Label and Message Editing

You’ve probably heard about the BuddyPress language file, but maybe you’e never taken the time to find out how it works and how it can help you customize your community. If you’re creating a highly customized niche network with BuddyPress, then the language file is going to be one of your most important and time-saving tools. It allows you to change text sitewide without digging into all of the code.

What is a language file?

A language translation file is not for translating international languages. It is used specifically for changing various labels and messages in BuddyPress in such a way that you don’t have to hack the core files. Otherwise you’d have to hack quite a few core files to  customize BuddyPress labels, messages, and URL slugs.  Not only is that time-consuming; it’s just not good practice. 

How Can I Use the BuddyPress Language File?

You can find the BuddyPress language file in buddypress/bp-languages/buddypress.pot. Copy that file and rename it to a .po extension – ie. buddypress-mysite.po. Now you can start editing it in a text file with the help of the search and replace function. Make sure you remember this critical bit of information:

Do not edit the “msgid” entries.

Edit only the “msgstr” entries.

For example, let’s say you want to change the message your users receive when they create a password that doesn’t match:

1
2
3
#: bp-core/bp-core-settings.php:84
msgid "Your passwords did not match"
msgstr "Oh noes! Your passwords don't match. Try again!"

Simple, isn’t it? Let’s do one more example just for fun. This would be if you’re creating more of a business networking site and you’d like to change “Friend” to “Associate” Here’s how you would edit one of the entries:

1
2
3
4
#: bp-friends/bp-friends-templatetags.php:143
#: bp-themes/bp-default/_inc/ajax.php:343
msgid "Add Friend"
msgstr "Connect to Associate"

Of course, you’re going to have to change more “Friend” instances in that scenario, but it’s not difficult. When you’ve finally completed all the editing on your language file, there’s one more step to making it work.

How to Create the .MO File

Upload your .po language file to: wp-content/plugins/buddypress/bp-languages. Now you need to run a command from the command line inside this directory to tell your server to create the .mo file. Login as root using a program such as PuTTY for Windows or Terminal.app for Mac. Depending on your server’s file structure, you’ll want to CD to this directory:

cd /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/buddypress/bp-languages

Now run the following command: msgfmt -o buddypress-mysite.mo buddypress-mysite.po

This will save the newly created .mo file in the /bp-languages/ directory for you.

Next step is to call the buddypress-mysite.mo file from wp-content/plugins/bp-custom.php like so:

1
2
3
4
define( 'BPLANG', 'mysite' );
if ( file_exists( BP_PLUGIN_DIR . '/bp-languages/buddypress-' . BPLANG . '.mo' ) ) {
    load_textdomain( 'buddypress', BP_PLUGIN_DIR . '/bp-languages/buddypress-' . BPLANG . '.mo' );
}

You’re done! Refresh your site and check out the changes.

When upgrading, if you use the automatic upgrade method to update BuddyPress, you should know that your custom language files will be removed. You’ll need to back those up before upgrading so that you can use them again. If you have any more questions, please ask in the comments or check out the BuddyPress Codex for more information.

Comments (15)

  1. I followed these instructions very closely to attempt to modify the language/text shown on my site. It didn’t work. The .mo file has been created. (When I ftp it to my computer and look at it in a text editor I see the line of text I have entered in the “msgstr” area where I wanted it to show. The text is preceeded and followed by “nul” (in a format I’m not familiar with and I didn’t mess with that file or try to upload it again, I just looked at it.) I did not have a bp-custom.php file so I created one identical to yours above (I also named my .po file identically to yours so that should be correct.) Any idea why mine might not be working?

    Also, if I get it working, what steps do I have to take to make further changes? Do I have to recreate the .mo file each time or will it update itself now if I change the buddypress-mysite.po file?

    Thanks a bunch.

  2. Vaughan – You will need to create it through the same process every time as only the .po file is directly editable. When you created the bp-custom.php file did you have the opening and closing php tags? Just checking because you said you copied mine above identically. You’ll need those tags. Let me know and I can try to help you troubleshoot it.

  3. Hi
    I tried to create the .mo file but I get a 500: Unknown command. I’m using cyberduck and the .po file has been uploaded but its just the problem of running the script to create the .mo file.

    I also tried to use Terminal but i can’t seem to get the write path to access my server.

    :(

  4. Thanks Sarah! It works like a charm! I managed to integrate a wordpress site running qTtranslate with Buddypress by adding these lines in my theme’s function.php file:

    /* translate BuddyPress using qTranslate*/
    if(function_exists(‘qtrans_getLanguage’)) define(BPLANG, qtrans_getLanguage());
    if ( file_exists( BP_PLUGIN_DIR . ‘/bp-languages/buddypress-’ . BPLANG . ‘.mo’ ) ) {
    load_textdomain( ‘buddypress’, BP_PLUGIN_DIR . ‘/bp-languages/buddypress-’ . BPLANG . ‘.mo’ );
    }

    So now I have a multilingual wordpress installation with Buddypress! Sharing this because it was so poorly documented on the web.
    Thanks again!

  5. Hi,

    Thanks for this it looks like it’s what I’m looking to do but please can you tell me if this method will work on the urls of the group pages – I want to change them to /discussion/ .

    Also I’ve noticed that this method is a couple of years old now. Do you know if it is still the only solution? It feels quite hacky to me…

    B

  6. Dear Sarah.
    I appreciate that these are clear instructions, but my technical knowledge deserted me here. I get scared of the horses when talking paths… I know it’s crap. I tried to use Poedit to create an .mo, but I’m not sure what has gone wrong (nothing at all happened, and it’s hard to diagnose nothing). So, I’d really like to apply Terminal as you suggest here. Can you expand a little more on the following – wd be much appreciated.

    “Depending on your server’s file structure, you’ll want to CD to this directory:
    cd /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/buddypress/bp-languages”

    What does “CD to this directory” involve me doing?

    Thanks,
    M

  7. This is awesome, I’m wondering if I may be so cheeky and ask for ready to go .mo file?

    Anybody already have translated .mo file where the “Friends” are changed into “Contacts” ?

    If so it would be highly appreciated if you could share this.

Participate