ZF-2914: gettext, empty string translates to the gettext file header information


Problem: When using the gettext adapter, an empty string ('') translates to the gettext file header information. When compared to the PHP native gettext functions I see that they do not have the same behaviour (empty string translates to empty string), and I'm assuming that the zend_translate behaviour is wrong.

I do not really want to translate an empty string, but stumbled upon this issue because of another bug in Zend_Form (ZF-2913) - I was a bit surprised to see the gettext file headers in my form. ;-)

Reproduction code:

require_once 'Zend/Translate.php';
$translate = new Zend_Translate('gettext', './');

.po-file (generated with poEdit):

msgid ""
msgstr ""
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"Language-Team: \n"
"PO-Revision-Date: 2008-03-18 15:24+0100\n"
"Last-Translator: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "hello"
msgstr "hei"

My suggestion for a solution (please consider that I don't know how gettext .mo-files are supposed to be parsed, so I don't know if the following really is the right thing to do): zend/translate/adapter/gettext.php line 134:

                $original = '';

replace with:

                $this->_translate[$locale][''] = '';
                $this->_gettextHeader = fread($this->_file, $transtemp[$count * 2 + 1]);


Please attach the mo file for detailed reproduction. How they are generated depends on the OS, and the used compiler. This has nothing to do with poEdit.

Generally ALL contents has to be parsed. The implementation from Zend uses the standard as defined by GNU and does not use PHP's implementation because it is problematic and has failures.

Ok... looking through your provided file and the original gettext GNU specification I can say that this behaviour is not a bug.

The empty string is translated into systems information as described in the GNU gettext specification as you can read here:…

"This also has another advantage, as the empty string in a PO file GNU gettext is usually translated into some system information attached to that particular MO file, and the empty string necessarily becomes the first in both the original and translated tables, making the system information very easy to find."

This means for us that this is not a bug, this is a undocumented feature ;-)