[wp-hackers] _e(), _() and __()
Dave
support at textbones.com
Mon Jul 5 17:57:42 UTC 2004
The GetText library was created for the GNU project when they wanted an
easy way for programmers to create multilingual open source software. It
uses a standard file format with the extension .po
gettext() is a function which accesses these standard format language
files. It would be silly (and unsightly) to have the gettext() function
called for every single outputted line, to in most cases it is given the
alias _().
In other words, any string passed through _() would become translated
into the user's local format.
Since PHP isn't often compiled with the Gettext library, it is not
widely used. The nice thing WordPress is doing is using a custom set of
functions that are/have been developed for reading the language files
directly, without the need for the Gettext library. This means they can
use the GetText format, without the need for having PHP compiled with
built-in GetText support.
The file format gets complicated because the .po file (Portable Object)
is converted into a binary format .mo file (Machine Object).
At some stage, the other part of the GetText library may be reproduced
in PHP. This side of the library is the part which extracts the strings
from the script (all the strings enclosed in the _() or gettext()
functions) and makes the whole process easier to update translations and
do most of the process automagically.
That's where my knowledge ends, but you can find all kinds of wonderful
information here:
http://www2.iro.umontreal.ca/~gnutra/po/HTML/gettext.html
Stephen O'Connor wrote:
>Okay, just peeked into phpxref... _() does absolutely nothing - it just
>returns whatever string it's given. I think I remember something about it
>being simply a backwards compatible thing (it's referenced 83 times, all in
>either the class-pop3.php or textile1.php. :)
>
>The __() returns a localized or translated string I think. Not exactly sure
>how that works. :\ _e() does the exact same thing, only it echo's what it's
>given.
>
>Whenever you have a question about functions you should check out the online
>version of phpxref. It's been a lifesaver for me.
>
>http://www.cenamayo.com/wpxref/nav.html?index.html
>
>- Stephen
>
>
>>From: hackers-bounces at wordpress.org
>>[mailto:hackers-bounces at wordpress.org]On Behalf Of
>>dave at xmouse.ithium.net
>>Sent: Saturday, July 03, 2004 8:27 AM
>>To: hackers at wordpress.org
>>Subject: [wp-hackers] _e(), _() and __()
>>
>>
>>I'm seeing these function calls all over the new WP code. I'm
>>aware what they
>>do: _ and __ just return the string passed to it whilst _e echoes
>>it, but why
>>are they in there at all?
>>
>>
More information about the hackers
mailing list