load_muplugin_textdomain

函数
load_muplugin_textdomain ( $domain, $mu_plugin_rel_path = '' )
参数
  • (string) $domain Text domain. Unique identifier for retrieving translated strings.
    Required:
  • (string) $mu_plugin_rel_path Optional. Relative to `WPMU_PLUGIN_DIR` directory in which the .mo file resides. Default empty string.
    Required:
    Default: (empty)
返回值
  • (bool) True when textdomain is successfully loaded, false otherwise.
定义位置
相关方法
load_plugin_textdomainload_default_textdomainload_textdomainload_theme_textdomainload_script_textdomain
引入
3.0.0
弃用
-

load_muplugin_textdomain: 这是WordPress中的一个函数,为一个必须使用的插件加载翻译文件。你可以用这个函数来翻译你的必用插件的模板文件和其他PHP代码中的字符串。

加载驻留在mu-plugins目录中的插件的翻译字符串。

function load_muplugin_textdomain( $domain, $mu_plugin_rel_path = '' ) {
	/** @var WP_Textdomain_Registry $wp_textdomain_registry */
	global $wp_textdomain_registry;

	/** This filter is documented in wp-includes/l10n.php */
	$locale = apply_filters( 'plugin_locale', determine_locale(), $domain );

	$mofile = $domain . '-' . $locale . '.mo';

	// Try to load from the languages directory first.
	if ( load_textdomain( $domain, WP_LANG_DIR . '/plugins/' . $mofile, $locale ) ) {
		return true;
	}

	$path = WPMU_PLUGIN_DIR . '/' . ltrim( $mu_plugin_rel_path, '/' );

	$wp_textdomain_registry->set_custom_path( $domain, $path );

	return load_textdomain( $domain, $path . '/' . $mofile, $locale );
}

常见问题

FAQs
查看更多 >