返回介绍

load_textdomain()

发布于 2017-09-11 01:41:51 字数 3693 浏览 1124 评论 0 收藏 0

load_textdomain( string $domain,  string $mofile )

Load a .mo file into the text domain $domain.


description

If the text domain already exists, the translations will be merged. If both sets have the same string, the translation from the original value will be taken.

On success, the .mo file will be placed in the $l10n global by $domain and will be a MO object.


参数

$domain

(string) (Required) Text domain. Unique identifier for retrieving translated strings.

$mofile

(string) (Required) Path to the .mo file.


返回值

(bool) True on success, false on failure.


源代码

File: wp-includes/l10n.php

function load_textdomain( $domain, $mofile ) {
	global $l10n, $l10n_unloaded;

	$l10n_unloaded = (array) $l10n_unloaded;

	/**
	 * Filters whether to override the .mo file loading.
	 *
	 * @since 2.9.0
	 *
	 * @param bool   $override Whether to override the .mo file loading. Default false.
	 * @param string $domain   Text domain. Unique identifier for retrieving translated strings.
	 * @param string $mofile   Path to the MO file.
	 */
	$plugin_override = apply_filters( 'override_load_textdomain', false, $domain, $mofile );

	if ( true == $plugin_override ) {
		unset( $l10n_unloaded[ $domain ] );

		return true;
	}

	/**
	 * Fires before the MO translation file is loaded.
	 *
	 * @since 2.9.0
	 *
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
	 * @param string $mofile Path to the .mo file.
	 */
	do_action( 'load_textdomain', $domain, $mofile );

	/**
	 * Filters MO file path for loading translations for a specific text domain.
	 *
	 * @since 2.9.0
	 *
	 * @param string $mofile Path to the MO file.
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
	 */
	$mofile = apply_filters( 'load_textdomain_mofile', $mofile, $domain );

	if ( !is_readable( $mofile ) ) return false;

	$mo = new MO();
	if ( !$mo->import_from_file( $mofile ) ) return false;

	if ( isset( $l10n[$domain] ) )
		$mo->merge_with( $l10n[$domain] );

	unset( $l10n_unloaded[ $domain ] );

	$l10n[$domain] = &$mo;

	return true;
}

更新日志

Versiondescription
1.5.0Introduced.

相关函数

Uses

  • wp-includes/l10n.php: override_load_textdomain
  • wp-includes/l10n.php: load_textdomain
  • wp-includes/l10n.php: load_textdomain_mofile
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/plugin.php: do_action()
  • wp-includes/pomo/mo.php: MO::import_from_file()
  • Show 1 more use Hide more uses

Used By

  • wp-includes/l10n.php: _load_textdomain_just_in_time()
  • wp-includes/l10n.php: load_default_textdomain()
  • wp-includes/l10n.php: load_plugin_textdomain()
  • wp-includes/l10n.php: load_muplugin_textdomain()
  • wp-includes/l10n.php: load_theme_textdomain()
  • wp-includes/load.php: wp_load_translations_early()
  • wp-includes/functions.php: wp_timezone_choice()
  • Show 2 more used by Hide more used by

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文