smhg / gettext-parser

Parse and compile gettext po and mo files, nothing more, nothing less
MIT License
158 stars 44 forks source link

msgid >= 77 characters produces incorrect output #6

Closed cbeley closed 9 years ago

cbeley commented 9 years ago
var gettextParser = require('gettext-parser');
var data = {
    "translations": {
        "": {
            "dfkjdfkljdfkljdskljdfklsjsdfkljdfsklsdjfklsdfjkldsfjdsflkjsdfkldsfjdskljdsfff": {
                "msgid": "dfkjdfkljdfkljdskljdfklsjsdfkljdfsklsdjfklsdfjkldsfjdsflkjsdfkldsfjdskljdsfff",
                "msgstr": []
            }
        }
    }
};

console.log(gettextParser.po.compile(data).toString());

Results in

msgid ""
msgstr "Content-Type: text/plain;\n"

msgid ""
"dfkjdfkljdfkljdskljdfklsjsdfkljdfsklsdjfklsdfjkldsfjdsflkjsdfkldsfjdskljdsdf"
"kjdfkljdfkljdskljdfklsjsdfkljdfsklsdjfklsdfjkldsfjdsflkjsdfkldsfjdskljdsdfkj"
"dfkljdfkljdskljdfklsjsdfkljdfsklsdjfklsdfjkldsfjdsflkjsdfkldsfjdskljds"
msgstr ""

The issue will not occure with 76 characters.

BYK commented 9 years ago

Why do you think this is incorrect? AFAIK this is the expected behavior. Consequent string blocks are automatically merged.

andris9 commented 9 years ago

I can't confirm this either. The output sure does look fishy as the msgid in the code and in the output do not match but when I run the sample code myself I get this output which is correct

msgid ""
msgstr "Content-Type: text/plain;\n"

msgid ""
"dfkjdfkljdfkljdskljdfklsjsdfkljdfsklsdjfklsdfjkldsfjdsflkjsdfkldsfjdskljdsff"
"f"
msgstr ""

I know that the string is folded kind of strangely but this is because the string is one long word. If it would contain spaces or punctuation marks, the folding would look lot nicer.

cbeley commented 9 years ago

Ah, well I'm sorry, I didn't realize that msgid could span multiple lines like that (looks kind of odd). Sorry for the false alarm!

EDIT: Sorry again for not double checking this. For anyone else who may run across this issue, see the bottom of https://www.gnu.org/software/gettext/manual/html_node/PO-Files.html that describes this output as valid.