将.mo文件加载到文本域$domain中。
load_textdomain(string $domain,string $mofile)
说明(Description)
如果文本域已经存在,则将合并翻译。如果两个集合都有相同的字符串,则将从原始值进行转换。
成功时,.mo文件将被$domain放入$l10n全局中,并成为一个mo对象。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$domain | (string) | 必需 | 文本域。检索转换字符串的唯一标识符。 |
$mofile | (string) | 必需 | .mo文件的路径。 |
返回(Return)
(bool)成功时正确,失败时错误。
源码(Source)
/**
* 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;
}
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
1.5.0 | wp-includes/l10n.php:627 | 7 | 6 |