NYCPHP Meetup

NYPHP.org

[nycphp-talk] gettext help

David Krings ramons at gmx.net
Sat Dec 15 11:30:10 EST 2007


Hi!

After creating a simple test project and going with xgettext at it I did 
successfully create the .po file, but found that concatenated strings aren't 
treated as one string. For example, I have this in my test script:
echo _("This is a string ".
        "that is concatenated ".
        "over three rows in one statement.");
xgettext reads that out as three individual strings. What I expected to happen 
is that a string within _() gets treated as one string and since I specified 
PHP as the language to deal with I further expected xgetttext to know how 
strings are concatenated in PHP and that any concatenated variables are to be 
ignored (although I haven't tested yet if it did that). I used the following 
command:
"C:\Program Files\Poedit\bin\xgettext.exe" -pF:\gettexttest\lang -a 
--language=PHP F:\gettexttest\*.php

I have concatenated strings all over the place after many people yelled at me 
that my lines in my scripts are longer than 80 chars. Any advice on how to 
make xgettext understand the dot?

Also, how can I specify an entire directory tree to be searched for php files 
rather than just one directory. I did see that one can specify the locations 
to be read from a file, but I couldn't find conclusive instructions on how to 
format that file.

I also tried using poedit to create the catalogs, but all I get is an error 
message that it couldn't find source files. The help doesn't really specify on 
where to set where to look for the source files.

I guess with some more time I could get used to gettext, but the motto "as 
simple as possible, but not simpler" requires that I redefine what I 
understand under "simple". What makes it even worse, the several tutorials 
that are available all have their own, often overly complicated approach. Most 
create extra functions and wrap functions into new functions.

I also wonder how gettext differentiates between text strings. It is possible 
that a string in two spots is the same for English, but different for German. 
Since gettext apparently keys off the english string, how can it differentiate?

Does anyone know of a good tutorial that doesn't try to get fancy in step 0?

While waiting for answers I will look into using ini file as string files. 
There are translation tools out there and ini files are simple enough to 
create one's own tools. Reading ini files is part of the php core...wait, 
wasn't there a discussion about this going on as well? The downside to that is 
that I'd need to create a new function and that I need to extract the strings 
manually, which in my case wouldn't be that horrible as there aren't that many.

Thanks in advance!

David



More information about the talk mailing list