Do you want to change various labels and messages in BuddyPress, but don’t want to hack the core files to do so? This page explains how to use a language translation file to customize BuddyPress labels, messages, and URL slugs.
Note: This is not intended for full language translations. If you intend BuddyPress to be used in a language other than English, see the Language Translations page.
Why use a language file?
The most compelling reason to use this method of changing labels and messages is to avoid hand-changing labels and messages in plugin and theme files. Even though theme customizations are recommended and encouraged, it is nice to have your customizations in one place. Overall, creating a custom language file is a better long-term solution than hand-changing plugin or theme files since you can make changes in one place for all labels and messages used in BuddyPress. (Note on upgrading: if you use the automatic upgrade method to update BuddyPress, be aware that your custom language files will be removed.)
Labels and Messages
Here are the steps to create your own custom messages and labels without doing a full language translation. This example uses mysite as the sample language definition, and thus buddypress-mysite.mo as the name of the language file you will create; you’ll need to replace ‘mysite’ with your own custom definition (make it whatever you want).
1. Create a customized PO file
Open the POT file from the bp-languages folder in your BuddyPress install, copy it to a PO file (by renaming it to have a .po extension). Then make the changes you want in a text editor or by using a specialized language localization editor like PoEdit (this is recommended if you are not comfortable using a text editor to make changes to the .po file).
For those of you using a text editor, although you can search and replace to make changes, make sure that you are not editing msgid entries. Your custom text goes into the lines labeled msgstr only. For each customization you’ll need to enter your customized text between the quotes on the msgstr line.
For example, to changing the label “Group Wire” to “Group Wall”, you’d look through the PO file until you find line 3502:
#: bp-themes/buddypress-member/groups/group-home.php:62 #: bp-themes/buddypress-member/groups/wire.php:26 msgid "Group Wire" msgstr "Group Wall"
2. Upload the PO file and create the MO file
Move the PO file to wp-content/plugins/buddypress/bp-languages on your server. Then, run the following command from the command line in the same directory. This will create the MO version of the language file.
msgfmt -o buddypress-mysite.mo buddypress-mysite.po
Note: running this command requires command line access to your server via a program like PuTTY (Windows), Terminal.app (Mac), or from inside an FTP program or Twitter Apps and requires that your server support the GNU gettext command msgfmt. If this is over your head (or you don’t know how to run commands like this, please see Translating WordPress for other software options for converting language files).
3. Load the MO language file with bp-custom.php
In your custom BuddyPress file (wp-content/plugins/bp-custom.php), add a custom language definition to load the language file.
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’ll notice that this is exactly how bp-core.php would load a site-wide language translation file. We’re doing the same thing here, but without changing the default language and locale (English).
Note: by putting the custom language file in the buddypress folder, you will lose all your changes when you upgrade BuddyPress. It is probably a safer idea to put your custom files in the plugins directory like this instead:
define( 'BPLANG', 'mysite' );
if ( file_exists( WP_PLUGIN_DIR . '/buddypress-' . BPLANG . '.mo' ) ) {
load_textdomain( 'buddypress', WP_PLUGIN_DIR . '/buddypress-' . BPLANG . '.mo' );
}
4. Test and verify your changes by loading BuddyPress.
Using Poedit
Poedit is a lightweight application for editing and creating .po and .mo files
If you are not comfortable working at the command line then it is highly recommended to use this application.
You can download a binary installer from sourceforge.net/projects/poedit/
Using Poedit for the first time
Start the application (it will ask for your name and email this to for catalog header information only)
On the main menu select File > new catalog from POT file navigate to the BP languages folder and select the
‘buddypress.pot’ file located there, this will open a ’settings’ dialog and you will be asked to fill in some details such as project name which we’ll skip; click on ‘OK’ and select a name for your new .po catalog file – Note! at this stage it will save the file to the BuddyPress languages directory which you may want to change. Having saved the file with the name of your choice you will now see all the BuddyPress language strings presented one after the other and below two split windows the top one shows the default BP string that is highlighted in the main screen at the top and the bottom screen is where you add the custom string that you want to replace it with.
Changing strings and saving the changes
If you select a string in the main window by right clicking it you will be asked if you wish to copy that string to the ‘Translation Field’ select this and it will place the string in the bottom split window, you can now edit this second string to a new value – Note! you do not need to save this change you will see the new string appear to the right of the original in the top screen after copying the string to the ‘Translation Field’ as you edit the text the changes are automatically reflected.
Move on to the next string and perform any edits you want. When you are finished simply select the icon ‘Save catalog’ this saves the catalog .po file and automatically generates the .mo file that BP will actually use. Note! you can save at any time and Poedit will simply overwrite the created files so it might be wise to follow the ‘Save often’ principle.
Your changes will come in to effect when you have followed the instructions given earlier on adding the necessary ‘custom language definition’ in your bp-custom.php file
Updating your custom language file
With new versions of BuddyPress will come new POT files with any new language strings that may be required. In order that your custom file remains up to date you will need to merge this new file to your custom .po catalog this is a simple task achieved in this fashion:
Open your custom .po catalog file you created, go to the ‘Catalog’ menu and select ‘Update from POT file…’ this should show you the POT file that resides in the BP languages directory but if you have followed earlier advise and saved your custom files in the plugin directory then navigate to the buddypress/bp-languages/ directory for the up to date POT file. Opening the file will show an ‘Update Summary’ window this shows you the new strings added and the Obsolete strings that will be removed click on ‘OK’ and these additions/deprecated items will merged into your .po catalog file, you then simply save your catalog file once more to save the changes and generate a new .mo file.
Slugs
You can also change BuddyPress URL slugs (e.g. example.com/members). To change the default slugs to something else, enter your custom slug definitions in your bp-custom.php file (these definitions can also go in your wp-config.php file).
For example, if you are running a sports website with BuddyPress, you could rename the URL slug example.com/members to example.com/players by adding the following line:
define( 'BP_MEMBERS_SLUG', 'players' );
The definable slugs as of BuddyPress 1.2.1 are as follows:
define( 'BP_ACTIVATION_SLUG', 'activate' ); define( 'BP_ACTIVITY_SLUG', 'activity' ); define( 'BP_BLOGS_SLUG', 'blogs' ); define( 'BP_FORUMS_SLUG', 'forums' ); define( 'BP_FRIENDS_SLUG', 'friends' ); define( 'BP_GROUPS_SLUG', 'groups' ); define( 'BP_MEMBERS_SLUG', 'members' ); define( 'BP_MESSAGES_SLUG', 'messages' ); define( 'BP_REGISTER_SLUG', 'register' ); define( 'BP_SEARCH_SLUG', 'search' ); define( 'BP_SETTINGS_SLUG', 'settings' ); define( 'BP_XPROFILE_SLUG', 'profile' );
Notes
This is not intended for full language translations. If you intend BuddyPress to be used in a language other than English, see the Language Translations page.
This solution is arguably better than using the define ( 'WPLANG', ''); declaration in your wp-config.php file since we are really just trying to customize BuddyPress and not WordPress MU as a whole.
This page was inspired by a forum topic on BuddyPress.org called I want to speak Spotlish. View that thread for discussion and other suggestions.