9

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/

  • 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

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 );
  • 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. – fuxia 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
2

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)

0

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.

-1

In my case creating permanent custom translation for the plugin requires following steps (examples for ACF plugin translation):

  1. create wp-content/languages/plugins/ directory
  2. copy selected translation file .po from the plugin lang/ folder (or any other with translations) to created wp-content/languages/plugins/ (e.g from lang/acf-pl_PL.po to wp-content/languages/plugins/acf-pl_PL.po)
  3. customize the translation with e.g. Poedit or any other program for editing .po files and then generate .mo and save in wp-content/languages/plugins/ (e.g. wp-content/languages/plugins/acf-pl_PL.mo)

This way the translation should be preserved even after plugin update.

I'm not sure if this strategy will work for all the plugins but this it's definitely worth trying.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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