Double Underscore in PHP?

梦想与她 提交于 2019-11-26 11:24:15

问题


What does the double underscores in these lines of PHP code mean?

$WPLD_Trans[\'Yes\']=__(\'Yes\',$WPLD_Domain);
$WPLD_Trans[\'No\']=__(\'No\',$WPLD_Domain);

回答1:


Looks like you're using Wordpress - wp-includes/l10n.php defines __ as a function that translates a string (similar to gettext and its alias, _ but with an optional parameter for explicitly specifying a domain).




回答2:


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.




回答3:


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

__();



回答4:


WordPress documents it's __() function, part of the localisation technology here: 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.




回答5:


A similar or third-party GNU gettext based implementation:

http://www.php.net/manual/en/function.gettext.php

Note: You may use the underscore character '_' as an alias to this function.



来源:https://stackoverflow.com/questions/1777131/double-underscore-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!