![](/img/trans.png)
[英]Problems with the Wordpress plugin translation, translation with .PO and .MO files does not work
[英]How to make custom Wordpress plugin aware of .po and .mo files?
我正在嘗試為從頭開始編寫的插件添加翻譯,但是經過一段時間的試驗后,我不確定如何使Wordpress意識到我的插件有翻譯可用。
我不確定還有什么嘗試的方法,所以我認為經驗豐富的人可能會指出我可能需要更改的內容。
到目前為止,我做了什么:
_e()
或__()
。 .pot
文件。 .pot
文件,(它顯示了我要翻譯的所有字符串的列表)翻譯后的插件,並從中生成了.po
和.mo
文件。 .pot
, .po
和.mo
移至my-plugin/languages/
。 my-plugin-pt.po
和my-plugin-pt.mo
。 不太確定下一步該怎么做。
我已經按照Wordpress的這些說明創建了一個運行load_plugin_textdomain()
的方法,並將其作為操作添加到my-plugin
__construct()
:
my-plugin.php
public function __construct() {
// Other filters and actions...
add_action( 'plugins_loaded', array( $this, 'translation_init' ) );
} // __construct
function translation_init() {
load_plugin_textdomain( 'my-plugin', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
.po
和.mo
文件末尾的語言代碼不正確。 從-pt.po
更改為-pt_PT.po
(與.mo
文件相同),它開始正常運行。
列出了Wordpress可用的語言代碼,在命名文件之前我應該先看一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.