__()检索来自translate()的被翻译过的字符串

目录

描述

译文

检索来自translate()的被翻译过的字符串

原文

Retrieves the translated string from the translate().

__() 描述

用法

<?php $translated_text __$text$domain ); ?>

__() 用法

参数

$text

(string) (必填) Text to translate

默认值: None

$domain

(string) (可选) Domain to retrieve the translated text

默认值: 'default'

__() 参数

返回值

(string) 

Translated text

__() 返回值

示例

Make a string inside your plugin or theme translatable:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

$translated = __( 'Hello World!', 'mytextdomain' );

'mytextdomain' needs to be a unique text domain used throughout your plugin/theme. This should always be directly passed as a string literal as shown above, not a string assigned to a variable or constant. E.g., this is incorrect:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

$text_domain = 'mytextdomain';
$string = 'Hello World!';
$translated = __( $string, $text_domain );

This seems to work, but it will interfere in automatic parsing of your plugin/theme's files for translation. See these for more information:

__() 示例

注意

  • See __() An alias of translate()
  • l10n is an abbreviation for localization.
  • The function name is two underscores in a row. In some fonts it looks like one long underscore. (Who says programmers don't have a sense of humor.)

__() 注意

历史

  • 添加于 版本: 2.1.0

__() 历史

源文件

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

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve the translation of $text. If there is no translation,
 * or the text domain isn't loaded, the original text is returned.
 *
 * @since 2.1.0
 *
 * @param string $text   Text to translate.
 * @param string $domain Optional. Text domain. Unique identifier for retrieving translated strings.
 * @return string Translated text.
 */
function __( $text, $domain = 'default' ) {
	return translate( $text, $domain );
}

__() 源文件

相关