duan1227 2018-05-18 12:21
浏览 112
已采纳

插件本地化无效

I've set up everything according to the docs and compiled my translations using loco translate. For some Reason, I can't get the translations to work. It always prints out english. How can I get the translations to work? I posted this question on stackoverflow because I'm not sure whether this is an issue with gettext, wordpress or my code.

<?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 file

#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: myplugin
"
"Report-Msgid-Bugs-To: 
"
"POT-Creation-Date: 2018-05-18 12:06+0000
"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE
"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>
"
"Language-Team: 
"
"Language: 
"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=UTF-8
"
"Content-Transfer-Encoding: 8bit
"
"X-Generator: Loco https://localise.biz/"

msgid "Learn more"
msgstr ""

.po file

msgid ""
msgstr ""
"Project-Id-Version: myplugin
"
"Report-Msgid-Bugs-To: 
"
"POT-Creation-Date: 2018-05-18 12:06+0000
"
"PO-Revision-Date: 2018-05-18 12:12+0000
"
"Last-Translator: Tom <tomm1996@gmail.com>
"
"Language-Team: Deutsch
"
"Language: de_DE
"
"Plural-Forms: nplurals=2; plural=n != 1;
"
"MIME-Version: 1.0
"
"Content-Type: text/plain; charset=UTF-8
"
"Content-Transfer-Encoding: 8bit
"
"X-Generator: Loco https://localise.biz/"
msgctxt "Link text"
msgid "Learn more"
msgstr "Erfahren Sie mehr."

WP Config

define('WPLANG', 'de_DE');
  • Wordpress Version: 4.9.6
  • PHP Version: php-5.6.4
  • 写回答

1条回答 默认 最新

  • dongyu7074 2018-05-22 08:19
    关注

    The problem was, that I used a hook to load the text-domain.

    By changing this:

    <?php
    add_action( 'plugins_loaded', 'loadMyPluginTextDomain');
    _e('Learn More', 'myplugin-domain');
    

    to this:

    <?php
    loadMyPluginTextDomain();
     _e('Learn More', 'myplugin-domain');
    

    I got it running. I'm just not sure whether not using the hooks has any negative effects on the plugin queue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?