使Loco翻译Wordpress插件来识别MU-PLUGINS

时间:2017-01-18 12:31:42

标签: wordpress localization

我在我的Wordpress 4.7安装中使用了Loco Translate翻译插件。

我的MU-Plugin已正确注册并正确配置为加载其文本域。

然而,Loco Translate只设法识别主题和常规插件,因此我无法使用Loco Translate UI来翻译我的插件。

帮助将不胜感激。 感谢

1 个答案:

答案 0 :(得分:1)

欢迎来到堆栈溢出Jonathan Darchy!

以下是将未注册的MU插件添加到Loco Translate的示例 Raw,取自this gist

我认为它回答了你的问题:

<?php
/**
 * MU plugins inside directories are not returned in `get_mu_plugins`.
 * This filter modifies the array obtained from Wordpress when Loco grabs it.
 * 
 * Note that this filter only runs once per script execution, because the value is cached.
 * Define the function *before* Loco Translate plugin is even included by WP.
 */
function add_unregistered_plugins_to_loco( array $plugins ){
    // we know the plugin by this handle, even if WordPress doesn't
    $handle = 'foo-bar/foo-bar.php';

    // fetch the plugin's meta data from the would-be plugin file
    $data = get_plugin_data( trailingslashit(WPMU_PLUGIN_DIR).$handle );

    // extra requirement of Loco - $handle must be resolvable to full path
    $data['basedir'] = WPMU_PLUGIN_DIR;

    // add to array and return back to Loco Translate
    $plugins[$handle] = $data;
    return $plugins;
}
add_filter('loco_plugins_data', 'add_unregistered_plugins_to_loco', 10, 1 );