How to create a theme specific translation of buddypress?

Originally asked on the BuddyPress forums:

For distribution purposes I would like to include my customized buddypress language files in my theme alongside my other language files. No matter what I try though I can only get the language files to display if I copy them over to wp-content/languages as described in the buddypress codex. I thought that the following would work, but it doesn’t:

Read More
function load_buddypress_language_files() {
    load_theme_textdomain('buddypress', get_template_directory() . '/lang');
}
add_action('plugins_loaded', 'load_buddypress_language_files');

This is possible isn’t it?

WP: 3.5.1 BP: 1.7.2

Related posts

1 comment

  1. First, actions added to plugins_loaded hook will not work from theme functions.php or any theme file because at that point it will be already fired (too late from theme files).

    What you can do is to hook your action into after_setup_theme and unload buddypress text domain first and then add your custom buddypress text domain file. The reason is that WordPress will not load any translation files for text domains that has already been added:

    add_action('after_setup_theme', 'replace_bp_mofile');
    
    function replace_bp_mofile() {
        $mo_file = get_stylesheet_directory() . '/languages/' . sprintf( 'buddypress-%s.mo', get_locale() );
        if (file_exists( $mo_file )) {
            unload_textdomain('buddypress');
            load_textdomain('buddypress', $mo_file);
        }   
    }
    

Comments are closed.