Блогчетање

Данилово блогче

Thu, 23 Oct 2003

Did you ever have problems with the lack of gettext support on your hosting provider? I surely did.

Did you ever have problems with using system-set locales on your hosting provider (eg. imagine using a "sr@Latn" locale on a system which doesn't even have sane "sr" locales)? I surely did.

So, what's the solution? You either don't have the root access to the system, or you don't want to bother installing all the software and locales just to make translations happen.

Well, there was a "fallback" library for reading MO files (products of GNU gettext msgfmt tool) for a long time in standard Python distribution, but there was none for PHP (at least I couldn't find it).

There WAS none, but there is one NOW! It's called PHP-gettext (am I not inventive?), and you can grab PHP-gettext 1.0.1[1] from my hacks collection. It's published under GPL, so it's free software. It also means that there's no warranty, and that it at least

Works For Me!

It's based on the description of MO file format in gettext info documentation. Doesn't provide all the background architecture of gettext proper, but it provides what you need most: using gettext() or _() calls, and using ngettext() calls. Oh yeah, it might be real slow for you — I didn't use it with project larger than 100 strings so far.

Some may consider it a feature, others may consider it a bug, but you can set the full path to the MO file that you want to read. This means that you have to take care of the administrativia of "gettext domains", "locales", etc. but in a sense where PHP is used, I consider it only a plus.

Anyway, check the lengthy README file (included) for all the details.

[1] There was a short-lived 1.0.0 version which is almost the same

[02:40] | [] | # | G | | TB
Very well. I used gettext few times from PHP and I think that gettext is the most powerfull i18n library.

I didn't tested your code yet, so I cannot say anything for speed of this-like implemented gettext support, but I am sure that this is good for small sized projects.

It is better than stupid usage of so called "lang files". It is more powerfull, in any way.
— Posted by Goran Rakić at Thu Oct 23 13:09:57 2003
Actually, the only bottleneck in speed so far is file reading speed. I need a readint32() function, but it seems PHP doesn't provide reading four bytes of file like an int, and choosing the byteorder you like. Because of this, I read byte-by-byte, and assemble an int myself. I tried playing with casting four-byte string to int, but that didn't work. Got any clue on how to speed it up?

Still, because of the nature of the MO file design, there's not much you can do to improve it, and I don't think it's too much slower than the standard library (apart from a one caching TODO).

If you care about the speed, there's a bunch of caching mechanism in my code, and I'm planning on adding some more. There are comments in the code that mention where should it be done, so you might try it yourself (in translate(), just add a check if some array [which you'll add to if there isn't] contains the translation for wanted string, and the same for ngettext()).
— Posted by Danilo Segan at Thu Oct 23 19:27:37 2003

Name:


E-mail:


URL:


Comment:


Contact
Danilo Segan

This is blog (web log) of Danilo Šegan (or Данило Шеган).

Archives
2017-Jan
2013-Dec
2011-Nov
2011-Oct
2011-Aug
2011-Jul
2011-Jun
2011-May
2010-Oct
2010-Aug
2010-Jul
2010-Apr
2010-Mar
2010-Feb
2010-Jan
2009-Dec
2009-Oct
2009-Aug
2009-Jun
2008-Oct
2008-Aug
2008-Jul
2008-Jun
2008-May
2008-Apr
2008-Mar
2008-Feb
2007-Dec
2007-Oct
2007-Aug
2007-Jul
2007-May
2007-Apr
2007-Feb
2007-Jan
2006-Nov
2006-Oct
2006-Aug
2006-Jul
2006-Apr
2006-Mar
2006-Feb
2006-Jan
2005-Sep
2005-Jun
2005-May
2005-Apr
2005-Mar
2005-Feb
2004-Dec
2004-Nov
2004-Oct
2004-Sep
2004-Aug
2004-Jul
2004-May
2004-Apr
2004-Mar
2004-Feb
2004-Jan
2003-Dec
2003-Nov
2003-Oct
2003-Sep
1983-Mar

< October 2003 >
MoTuWeThFrSaSu
   1 2 3 4 5
6 7 8 9101112
13141516171819
20212223242526
2728293031  
Categories

Links
Kvota.net
Prevod.org
My study page
Srpski.org
GNOME
Friends' Blogs
alex (en)
bc (en)
Bojan Živanović (sr)
Carlos (en)
Goran (sr)
imp (sr)
lilit (sr)
Oskuro (en)
Zombie (sr/en)
Feeds
RSS