[nycphp-talk] gettext help
David Krings
ramons at gmx.net
Sat Dec 15 20:02:16 EST 2007
Hi!
First of all, thanks John for your reply. Yes, I do use the WAMPP stack, which
in several tests happened to come up on top in regards to performance compared
to LAMPP and IIS. I am not surprised that it performs better than IIS, but was
suprised about the LAMPP. Although, performance wasn't the reason I chose it.
I have a W2k Pro box with server SCSI drives that is rock solid and runs for
months without problems. My record is 9 months without reboot, unheard of in
the Windows world. And if there is a reboot, it is because Patch Tuesday.
I did dig a bit deeper into gettext and the tools that are available on *nix
are mostly ported to doze as well. I got tired of the resulting .po files to
be littered with all kinds of string garbage or less than half the strings no
matter what I did.
Plan B was writing two simple functions, one that reads in a specified ini
file into an array, and when a section was specified, returns only that
section while ditching the remains. The second function accepts a key and a
default string (the current english string) and has to get passed on the array
with the strings. I crafted an ini file with 300 entries and strings that each
are about 200 chars. In my first test I had PHP barf up the entire array, then
in a second test pick out random strings. I braced for the worst, but turns
out that this is really fast.
My plan is to create sections for each script that generates output, read in
the file, then based on the name of the script keep the required section and
throw the rest away (hoping that PHP releases the memory used). Overall, the
two functions are less than a dozen lines of code.
That approach has two disadvantages. The code once instrumented gets more
difficult to read, but using some one or two letter name for my function and a
short array name will condense the calls. It is not as short as _(), well, I
could name my function _, but I don't think that is a good idea. Maybe ~() or
€() isn't taken yet. The other disadvantage is the manual string extraction,
but I need to rework all echos anyway and given the state of the .po files
those would need some massive manual cleanup work as well.
My scripts aren't as logic / display separated as they could be, but I do make
a point in preparing everything first and then focus on output as much as
possible, but still, it is sometimes within the same script. I go with the ini
file approach and see how that works out. The tests worked much better than I
expected. I then can also expand the functions to accept additional parameters
if needed.
David
More information about the talk
mailing list