Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

http://wordpress.org/extend/plugins/bbpress/ bbpress' language folder ( wp-content/plugins/bbpress/bbp-languages ) have that warning:

/**
 * Do not put custom translations here. They will be deleted on bbPress updates.
 *
 * Keep custom bbPress translations in /wp-content/languages/
 */

Actually this is not a new problem and yes they are right. This is big problem if you are using wordpress plugins with a non-english language.

Basically i translated bbpress and created .po and .mo files. Files are working if i put them in their normal wp-content/plugins/bbpress/bbp-languages folder. But as above warning says that will delete when update. But problem is, translating is not working if i put them in wp-content/languages/ folder as suggested in bbpress.

I think there must be a hook or something i can activate it but what is best solution for it? Simply i want to keep plugin language files in wp-content/languages/

share|improve this question
    
well.. after i check bbpress codes.. it seems i need to put files in /wp-content/languages/bbpress/ not in directly /wp-content/languages/ Now it works for bbpress but question is still need to get answer for other plugins imo –  Ünsal Korkmaz Oct 8 '11 at 16:44

3 Answers 3

up vote 3 down vote accepted

You have to replace the call to BBpress’ language file.

A good place to do this is a language specific file in your general languages directory. For Turkish it would probably be a file named tr_TR.php. This will be loaded automatically and only if it matches the language of your blog. It will not be overwritten.

BBPress doesn’t use the function load_plugin_textdomain, it uses load_textdomain instead. Here you can find a filter:

$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );

So in your language php file just add a filter to change the path:

function load_bbpress_tr_mofile( $mofile, $domain )
{
    if ( 'bbpress' == $domain )
    {
        // replace this. :)
        return 'FULL_PATH_TO_YOUR_FILE';
    }
    return $mofile;
}
add_filter( 'load_textdomain_mofile', 'load_bbpress_tr_mofile', 10, 2 );
share|improve this answer
    
seems there is a bug.. bbpress.trac.wordpress.org/ticket/1647 looking into it.. i will use default language folder wp-content/languages/ so whats your suggestion for'FULL_PATH_TO_YOUR_FILE'? –  Ünsal Korkmaz Oct 8 '11 at 16:24
    
The path to your language directory (WP_LANG_DIR) plus your mo-file. –  toscho Oct 8 '11 at 17:04
1  
Good answer. Note to plugin developers: do your load_plugin_textdomain() calls during the "init" action, otherwise we can't hook into the "load_textdomain_mofile" filter. It'll be too late already then. –  Geert Mar 1 '12 at 11:36

What you have to do is to create a simple plugin that will manage the text_domain of the installed plugins. If you don't want to have a global solution you can add the code to your functions.php in your theme.

The idea is to instruct wordpress on where to find translations. Internally in all plugins this is done using something similar to

load_plugin_textdomain( 'regenerate-thumbnails', false, '/regenerate-thumbnails/localization' );

this is the function that you will use. As you can see here, the last argument is used to set the relative to the plugin path, where the translation files reside.

You can do what you want by putting one line for each plugin you want to alter their languages folder as follows.

load_plugin_textdomain('bbpress', false, '../../languages/bbpress');

this will instruct wordpress to load your custom translation files from a folder next to plugins folder that has a folder named bbpress that has the translation files using the EXACT same naming as each plugin uses.

Your method, that instructs the textdomains for all plugins, should run in the init phase as follows

function set_myplugins_languages() {
     .... your code here.....
}
add_action('init', 'set_myplugins_languages');

(Don't forget to mark this as answer if you found it useful)

share|improve this answer

In order for this to work you need to have the WordPress translation files in the WP_LANG_DIR already, and have the global locale set to that language. If you're only including translations for bbPress without changing the locale or having WordPress's core translation files present, nothing will translate despite you loading them.

If you wish to override the locale for bbPress alone, you need to add a filter to 'bbpress_locale' which allows you to override the bbPress mo file.

While it's true that bbPress 2.0 uses the load_textdomain() function, load_plugin_textdomain() is just a wrapper for load_textdomain() anyways. The bbPress 2.0 method is more robust and allows for global translation file placement, so you don't lose them during plugin update.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.