meder omuraliev meder omuraliev - 29 days ago 7
PHP Question

How could I parse gettext .mo files in PHP4 without relying on setlocale/locales at all?

I made a couple related threads but this is the one direct question that I'm seeking the answer for. My framework will use

Zend_Translate
if the php version is 5, otherwise I have to mimic the functionality for 4.

It seems that pretty much every implementation of gettext relies on setlocale or locales, I know there's a LOT of inconsistency across systems which is why I don't want to rely upon it.

I've tried a couple times to get the
textdomain
,
bindtextdomain
and
gettext
functions to work but I've always needed to invoke
setlocale
.

By the way, all the .mo files will be UTF-8.

Answer

Ok, I basically ended up writing a mo file parser based on Zend's Gettext Adapter, as far as I know gettext is pretty much reliant upon the locale, so manually parsing the .mo file would save the hassle of running into odd circumstances with locale issues with setlocale. I also plan on parsing the Zend Locale data provided in the form of xml files.