load_textdomain()将MO文件加载到域名列表中

目录

描述

译文

将MO文件加载到域名列表中。

如果域名已经存在,则加载失败。如果MO文件不可读,加载也以失败告终。

加载成功后,MO文件会被$domain存储在全局变量$110n中,并成为gettext_reader的一个对象。

原文

Loads MO file into the list of domains.

If the domain already exists, the inclusion will fail. If the MO file is not readable, the inclusion will fail.

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

load_textdomain() 描述

用法

<?php load_textdomain$domain$mofile ?>

load_textdomain() 用法

参数

$domain

(string) (必填) Unique identifier for retrieving translated strings

默认值: None

$mofile

(string) (必填) Path to the .mo file

默认值: None

load_textdomain() 参数

返回值

(boolean

First, will return true and exit if call to apply_filters('override_load_textdomain') returns true. If .mo file is not readable or the import fails - returns false. Otherwise returns true.

load_textdomain() 返回值

注意

  • 使用到 global: (array) $l10n. Gets list of domain translated string objects.
  • l10n is an abbreviation for localization. There are 10 characters between the initial 'l' and the terminal 'n'

load_textdomain() 注意

历史

添加于 版本: 1.5.0

load_textdomain() 历史

源文件

load_textdomain() 函数的代码位于 wp-includes/l10n.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Load a .mo file into the text domain $domain.
 *
 * 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.
 *
 * @since 1.5.0
 *
 * @global array $l10n
 *
 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
 * @param string $mofile Path to the .mo file.
 * @return bool True on success, false on failure.
 */
function load_textdomain( $domain, $mofile ) {
	global $l10n;

	/**
	 * Filter text domain and/or MO file path for loading translations.
	 *
	 * @since 2.9.0
	 *
	 * @param bool   $override Whether to override the text domain. 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 ) {
		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 );

	/**
	 * Filter 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] );

	$l10n[$domain] = &$mo;

	return true;
}

load_textdomain() 源文件

相关