php PHP中的双下划线?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1777131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Double Underscore in PHP?
提问by Drahcir
What does the double underscores in these lines of PHP code mean?
这几行 PHP 代码中的双下划线是什么意思?
$WPLD_Trans['Yes']=__('Yes',$WPLD_Domain);
$WPLD_Trans['No']=__('No',$WPLD_Domain);
回答by SimonJ
Looks like you're using Wordpress - wp-includes/l10n.phpdefines __ as a function that translates a string (similar to gettextand its alias, _but with an optional parameter for explicitly specifying a domain).
看起来您正在使用 Wordpress -wp-includes/l10n.php将 __ 定义为一个转换字符串的函数(类似于gettext及其别名,_但具有用于显式指定域的可选参数)。
回答by Mike B
Strictly speaking, it means nothing in PHP as it is not a pre-defined function. However, in many frameworks, like CakePHP, and other libraries the double underscore is a function used for translating strings based on the user's language/locale preference.
严格来说,它在 PHP 中没有任何意义,因为它不是预定义的函数。但是,在许多框架中,例如 CakePHP 和其他库,双下划线是用于根据用户的语言/区域设置首选项翻译字符串的函数。
回答by JasonDavis
As mentioned it is generally used for translating text between languages but really it is used in the same context as any function call.
如前所述,它通常用于在语言之间翻译文本,但实际上它与任何函数调用在相同的上下文中使用。
testfunction();
is no different then
没有什么不同
__();
回答by PaulH
WordPress documents it's __() function, part of the localisation technology here: https://make.wordpress.org/polyglots/handbook/translating/working-with-core/#localization-technology
WordPress 文档它是 __() 函数,这里是本地化技术的一部分:https: //make.wordpress.org/polyglots/handbook/translating/working-with-core/#localization-technology
It is difficult to find documentation because __(), __('') or __("") is not very searchable, double underscore and parentheses (round brackets) are keywords to use.
很难找到文档,因为 __()、__('') 或 __("") 不是很容易搜索,双下划线和括号(圆括号)是要使用的关键字。
回答by knoopx
A similar or third-party GNU gettextbased implementation:
类似或第三方基于GNU gettext的实现:
http://www.php.net/manual/en/function.gettext.php
http://www.php.net/manual/en/function.gettext.php
Note: You may use the underscore character '_' as an alias to this function.
注意:您可以使用下划线字符“_”作为该函数的别名。

