Double underscore in PHP?

What do double underscores mean in these lines of PHP code?

$WPLD_Trans['Yes']=__('Yes',$WPLD_Domain); $WPLD_Trans['No']=__('No',$WPLD_Domain); 
+42
php double-underscore
Nov 21 '09 at 23:25
source share
5 answers

It looks like you are 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 specifying the domain explicitly).

+54
Nov 21 '09 at 23:33
source share

Strictly speaking, this does not mean anything in PHP, since it is not a predefined function. However, in many environments, such as CakePHP and other libraries, double underlining is a function used to translate strings based on a user language / language preference.

+35
Nov 21 '09 at 23:30
source share

As already mentioned, it is usually used to translate text between languages, but in fact it is used in the same context as any function call.

 testfunction(); 

no different from

 __(); 
+5
Nov 21 '09 at 23:37
source share

WordPress documents its __ () function, part of the localization technology here: https://make.wordpress.org/polyglots/handbook/translating/working-with-core/#localization-technology

It’s hard to find documentation because __ (), __ ('') or __ ("") are not very searchable, double underscores and parentheses (parentheses) are keywords to use.

+4
Jan 17 '15 at 21:04
source share

A similar or third-party GNU gettext implementation :

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

Note. You can use the underscore character '_' as an alias for this function.

+2
Nov 21 '09 at 23:49
source share



All Articles