load_textdomain
函数
load_textdomain ( $domain, $mofile, $locale = null )
- 参数
-
-
(string)
$domain
Text domain. Unique identifier for retrieving translated strings.- Required: 是
-
(string)
$mofile
Path to the .mo file.- Required: 是
-
(string)
$locale
Optional. Locale. Default is the current locale.- Required: 否
- Default: null
-
(string)
- 返回值
-
- (bool) True on success, false on failure.
- 定义位置
-
-
wp-includes/l10n.php
, line 718
-
wp-includes/l10n.php
- 引入
- 1.5.0
- 弃用
- –
将一个.mo文件加载到文本域$domain中。
如果该文本域已经存在,翻译将被合并。如果两组都有相同的字符串,将采取原始值的翻译。
一旦成功,.mo文件将被$domain放在$l10n全局中,并成为一个MO对象。
function load_textdomain( $domain, $mofile, $locale = null ) {
/** @var WP_Textdomain_Registry $wp_textdomain_registry */
global $l10n, $l10n_unloaded, $wp_textdomain_registry;
$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 === (bool) $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;
}
if ( ! $locale ) {
$locale = determine_locale();
}
$mo = new MO();
if ( ! $mo->import_from_file( $mofile ) ) {
$wp_textdomain_registry->set( $domain, $locale, false );
return false;
}
if ( isset( $l10n[ $domain ] ) ) {
$mo->merge_with( $l10n[ $domain ] );
}
unset( $l10n_unloaded[ $domain ] );
$l10n[ $domain ] = &$mo;
$wp_textdomain_registry->set( $domain, $locale, dirname( $mofile ) );
return true;
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


