NYCPHP Meetup

NYPHP.org

[nycphp-talk] gettext help

David Krings ramons at gmx.net
Sun Dec 16 08:52:52 EST 2007


John Campbell wrote:
>>  but € is fine.
> 
> I don't have one of those on my keyboard... You might want to pick
> something that is in 7-bit ascii to avoid character set problems.  T()
> seems like a good name.

Well, you need to get a better keyboard then, one that has an Alt Gr key and 
none of these windows buttons like my good 'ol Cheery. It is the first 
keyboard I ever bought (about 20 years ago). ;) I change it, it was more 
curiosity and a futile attempt at being kewl than rational thinking.

> It is unfortunate that you are giving up on gettext.  I am sure your
> solution will work, but I think in the long run it is going to be
> extra effort because the function now has 3 parameters rather than
> one.  You also don't need to bother testing performance on
> 200x300=60kb of data.  No matter what you do, it will be fast.  Once
> you have 1Mb of data, then there will start to be a difference because
> gettext will use 1Mb of memory per language, and your solution will
> write 1Mb to memory every request.  Btw, how are you testing
> performance?  Pure php, ab, or something else?
> 
Oh, the super scientific method of running it in the debugger and see what 
happens. I found that pulling it through the debugger makes everything extra 
slow compared to the production system (not that I expected it any different). 
I have some sections that take about a second from request to page display, 
but on the production side it is an unnoticeable delay. I could put in 
measures using microtime or such, but since I do not have a base line that 
becomes useless, nothing to compare it to. This was really just a subjective test.
Also, the ini file approach has one big and one smaller advantage over 
gettext: one does not have to restart the web server in order to load the 
updated strings and one also does not need the gettext extension to be enabled.
The three parameters are something I am not too happy about, ideally it would 
have been two, the key and the default string, which is optional. But I need 
to pass the array to the function otherwise the function doesn't know anything 
about that array. I could make it global, which saves four characters in the call.
1 MB of strings is a lot. I worked on professional desktop apps that had 
external string files and those were 400 or 500 kB max. You also got to see 
how much stuff gettext puts around each string (useful stuff). Using integer 
keys cuts down on data size to be handled right there. Although, when you say 
"1 Mb of data", do you mean mbit or mbyte (your notation indicates mbit)? And 
does that refer to file size or data size of strings only? In any case, I 
doubt that I will end up with that many strings for my app either way.
I think gettext is a good solution per sé, but the tools wrapped around it are 
lacking a bit of comfort. What would be nice is to have a parser go through 
the PHP files and allow for manual intervention right there allowing to reject 
strings and combine concatenated, while after accepting a string the source 
code gets updated to use the correct call. When trofitting one has to touch 
each string anyway.

Well, let's see with how many strings I end up. I think that I will first work 
on my CSH functions so that I can put that in as well while crawling through 
the code.


David



More information about the talk mailing list