bbPress‘ language folder (wp-content/plugins/bbpress/bbp-languages
) has 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 a 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 the above warning says, they will delete on update. But the problem is translations are not working if I put them in the wp-content/languages/
folder as suggested in bbPress.
I think there must be a hook or something I can activate it but what is the best solution for it? Simply I want to keep plugin language files in wp-content/languages/
.
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 usesload_textdomain
instead. Here you can find a filter:So in your language php file just add a filter to change the path:
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
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.
this will instruct wordpress to load your custom translation files from a folder next to
plugins
folder that has a folder namedbbpress
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(Don’t forget to mark this as answer if you found it useful)
In my case creating permanent custom translation for the plugin requires following steps (examples for ACF plugin translation):
wp-content/languages/plugins/
directory.po
from the pluginlang/
folder (or any other with translations) to createdwp-content/languages/plugins/
(e.g fromlang/acf-pl_PL.po
towp-content/languages/plugins/acf-pl_PL.po
).po
files and then generate.mo
and save inwp-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.
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.