問題描述
http://wordpress.org/extend/plugins/bbpress/ bbpress’ 語言資料夾 (wp-content /plugins /bbpress /bbp-languages) 有警告:
/**
* Do not put custom translations here. They will be deleted on bbPress updates.
*
* Keep custom bbPress translations in /wp-content/languages/
*/
其實這不是一個新問題,是的,他們是對的。如果您使用具有 non-english 語言的 wordpress 外掛,這是一個很大的問題。
基本上我翻譯 bbpress 並建立了.po 和.mo 檔案。如果我把它們放在正常的 wp-content /plugins /bbpress /bbp-languages 資料夾中,檔案正常工作。但是如上所述,警告說會在更新時刪除。但問題是,如果我把它們放在 wp-content /languages /資料夾中,如 bbpress 所示,翻譯是不行的。
我認為必須有一個鉤子或東西,我可以啟用它,但什麼是最好的解決方案呢?只要我想保留外掛語言檔案在 wp-content /languages /
最佳解決方案
您必須將呼叫替換為 BBpress 的語言檔案。
執行此操作的好地方是通用語言目錄中的特定於語言的檔案。對於土耳其語來說,它可能是一個名為 tr_TR.php 的檔案。這將自動載入,只有當它符合您的部落格的語言。它不會被覆蓋
BBPress 不使用 load_plugin_textdomain 功能,而是使用 load_textdomain 。在這裡你可以找到一個過濾器:
$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );
所以在你的語言 php 檔案中只需新增一個過濾器即可更改路徑:
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 );
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。