load_textdomain() - WordPress 函数参考中文文档

返回介绍

load_textdomain()

发布于 2017-09-11 字数3695 浏览 975 评论 0

load_textdomain( string $domain,  string $mofile )

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.


参数

$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;
}

更新日志

Version 描述
1.5.0 Introduced.

相关函数

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

上一篇:load_template()

下一篇:load_theme_textdomain()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!