插件本地化不起作用
Plugin Localization not working
我已经根据文档设置了所有内容,并使用 loco translate 编译了我的翻译。出于某种原因,我无法让翻译工作。它总是打印出英文。我怎样才能让翻译工作?我在 Whosebug 上发布了这个问题,因为我不确定这是 gettext、wordpress 还是我的代码的问题。
<?php
/**
* Plugin Name: myplugin
* Description: myplugindescription
* Author: Tom McLean
* Version: 1.0.0
* Text Domain: myplugin-domain
* Domain Path: /languages/
*/
function loadMyPluginTextDomain() {
load_plugin_textdomain(
'myplugin-domain',
false,
dirname(plugin_basename( __FILE__ )) . '/languages/'
);
}
add_action( 'plugins_loaded', 'loadMyPluginTextDomain');
_e('Learn More', 'myplugin-domain');
.pot 文件
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: myplugin\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-05-18 12:06+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: \n"
"Language: \n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Loco https://localise.biz/"
msgid "Learn more"
msgstr ""
.po 文件
msgid ""
msgstr ""
"Project-Id-Version: myplugin\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-05-18 12:06+0000\n"
"PO-Revision-Date: 2018-05-18 12:12+0000\n"
"Last-Translator: Tom <tomm1996@gmail.com>\n"
"Language-Team: Deutsch\n"
"Language: de_DE\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Loco https://localise.biz/"
msgctxt "Link text"
msgid "Learn more"
msgstr "Erfahren Sie mehr."
WP 配置
define('WPLANG', 'de_DE');
- WordPress 版本:4.9.6
- PHP版本:php-5.6.4
问题是,我使用了一个钩子来加载文本域。
通过改变这个:
<?php
add_action( 'plugins_loaded', 'loadMyPluginTextDomain');
_e('Learn More', 'myplugin-domain');
对此:
<?php
loadMyPluginTextDomain();
_e('Learn More', 'myplugin-domain');
我明白了运行。我只是不确定不使用钩子是否对插件队列有任何负面影响。
我已经根据文档设置了所有内容,并使用 loco translate 编译了我的翻译。出于某种原因,我无法让翻译工作。它总是打印出英文。我怎样才能让翻译工作?我在 Whosebug 上发布了这个问题,因为我不确定这是 gettext、wordpress 还是我的代码的问题。
<?php
/**
* Plugin Name: myplugin
* Description: myplugindescription
* Author: Tom McLean
* Version: 1.0.0
* Text Domain: myplugin-domain
* Domain Path: /languages/
*/
function loadMyPluginTextDomain() {
load_plugin_textdomain(
'myplugin-domain',
false,
dirname(plugin_basename( __FILE__ )) . '/languages/'
);
}
add_action( 'plugins_loaded', 'loadMyPluginTextDomain');
_e('Learn More', 'myplugin-domain');
.pot 文件
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: myplugin\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-05-18 12:06+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: \n"
"Language: \n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Loco https://localise.biz/"
msgid "Learn more"
msgstr ""
.po 文件
msgid ""
msgstr ""
"Project-Id-Version: myplugin\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-05-18 12:06+0000\n"
"PO-Revision-Date: 2018-05-18 12:12+0000\n"
"Last-Translator: Tom <tomm1996@gmail.com>\n"
"Language-Team: Deutsch\n"
"Language: de_DE\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Loco https://localise.biz/"
msgctxt "Link text"
msgid "Learn more"
msgstr "Erfahren Sie mehr."
WP 配置
define('WPLANG', 'de_DE');
- WordPress 版本:4.9.6
- PHP版本:php-5.6.4
问题是,我使用了一个钩子来加载文本域。
通过改变这个:
<?php
add_action( 'plugins_loaded', 'loadMyPluginTextDomain');
_e('Learn More', 'myplugin-domain');
对此:
<?php
loadMyPluginTextDomain();
_e('Learn More', 'myplugin-domain');
我明白了运行。我只是不确定不使用钩子是否对插件队列有任何负面影响。