WordPress函数:load_theme_textdomain 加载翻译的字符串

江河/ 03月28日/ WordPress/ 浏览 177

函数原型:


load_theme_textdomain( string $domain, string|false $path = false ): bool


加载WordPress主题中翻译的字符串


如果当前区域设置以.mo文件的形式存在于主题的根目录中,则$domain会将其包含在已翻译的字符串中。

.mo文件的命名必须完全基于区域设置。


参数说明:


$domain 翻译字符串的唯一标识


$path .mo 文件的路径


函数源码:


function load_theme_textdomain( $domain, $path = false ) {
	/** @var WP_Textdomain_Registry $wp_textdomain_registry */
	global $wp_textdomain_registry;

	/**
	 * Filters a theme's locale.
	 *
	 * @since 3.0.0
	 *
	 * @param string $locale The theme's current locale.
	 * @param string $domain Text domain. Unique identifier for retrieving translated strings.
	 */
	$locale = apply_filters( 'theme_locale', determine_locale(), $domain );

	$mofile = $domain . '-' . $locale . '.mo';

	// Try to load from the languages directory first.
	if ( load_textdomain( $domain, WP_LANG_DIR . '/themes/' . $mofile, $locale ) ) {
		return true;
	}

	if ( ! $path ) {
		$path = get_template_directory();
	}

	$wp_textdomain_registry->set_custom_path( $domain, $path );

	return load_textdomain( $domain, $path . '/' . $locale . '.mo', $locale );
}


包含钩子:


apply_filters( ‘theme_locale’, string $locale, string $domain )



发表评论

暂无评论,抢个沙发...

客服 工单