admin管理员组文章数量:1295723
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/
.
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/
.
- 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 Commented Oct 8, 2011 at 16:44
4 Answers
Reset to default 3You 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 );
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)
In my case creating permanent custom translation for the plugin requires following steps (examples for ACF plugin translation):
- create
wp-content/languages/plugins/
directory - copy selected translation file
.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
) - customize the translation with e.g. Poedit or any other program for editing
.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.
本文标签: multi languageHow to keep plugin translations after updates
版权声明:本文标题:multi language - How to keep plugin translations after updates? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741624338a2388996.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论