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. ;-)
require_once 'Zend/Translate.php'; $translate = new Zend_Translate('gettext', './nb.mo'); var_dump($translate->_(''));
.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 = '';
$this->_translate[$locale][''] = ''; $this->_gettextHeader = fread($this->_file, $transtemp[$count * 2 + 1]); continue;