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

Issue Type: Bug Created: 2008-03-18T11:37:26.000+0000 Last Updated: 2008-03-24T09:04:59.000+0000 Status: Resolved Fix version(s): - 1.5.3 (28/Jul/08)

Reporter: EV (evalder) Assignee: Thomas Weidner (thomas) Tags: - Zend_Translate

Related issues: Attachments: -


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:

<pre class="highlight">
require_once 'Zend/Translate.php';
$translate = new Zend_Translate('gettext', './');

.po-file (generated with poEdit):

<pre class="highlight">
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:

<pre class="highlight">
                $original = '';

replace with:

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


Posted by Thomas Weidner (thomas) on 2008-03-18T14:29:34.000+0000

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.

Posted by Thomas Weidner (thomas) on 2008-03-24T09:04:35.000+0000

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 ;-)

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.