tags:

views:

76

answers:

2

I noticed this piece of code in Wordpress 2.9.1 (/wp-includes/compat.php), I don't understand it:

if ( !function_exists('_') ) {
  function _($string) {
    return $string;
  }
}

It seems that PHP indeed has a function _($string) but I can't find the documentation for it.

+5  A: 

It is an alias for gettext()

AJ
and therefore used for localization.
contagious
/me nods in agreement
AJ
+2  A: 

_ is an alias for the gettext function for translating.

gettext takes the original string as input, and finds the translation for it. This approach has the advantage that if a translation does not exist, you'll get a sensible default string out of it.

To mirror this property, the code you found essentially creates an "always failing" version of this function in case gettext isn't available.

Michael Madsen