ZF-4085: wrong xml encoding detection mechanism in Zend_Translate_Adapter_Xliff throwing Zend_Translate_Exception: XML error: No error at line 0
If you use the following header for xliff files: <?xml version='1.0' encoding='utf-8'?> instead of <?xml version="1.0" encoding="utf-8"?> (i.e. single quotes instead of double quotes for "enconding" attribute value) you end up with the following exception: Fatal error: Uncaught exception 'Zend_Translate_Exception' with message 'XML error: No error at line 0' in /home/remy/my_php/ZendFramework-1.5.3/library/Zend/Translate/Adapter/Xliff.php:97 Stack trace:
0 ZendFramework-1.5.3/library/Zend/Translate/Adapter.php(406): Zend_Translate_Adapter_Xliff->_loadTranslationData('../application/...', 'en', Array)
My xliff file has been generated by translate-toolkit (part of pootle project), using po2xliff python script. At first I thought that all attribute values had to be wrapped into double quotes (cf. http://bugs.locamotion.org/show_bug.cgi?id=492) but single quotes appear to be legal too (cf. http://www.w3.org/TR/REC-xml/#NT-EncodingDecl).
Error comes from Zend_Translate_Adapter_Xliff->_findEncoding() method which tries to extract xml encoding from xliff file, but expect encoding value to be wrapped using double-quotes: line 195: $encoding = substr($encoding, 0, strpos($encoding, '"'));
One solution could be "$encoding = substr($encoding, 0, min(strpos($encoding, '"'), strpos($encoding, "'")));" since no single quote is to be found in any valid encoding value.