arashm/PoParser

plural forms header entry should not be added empty if missing

dfherr opened this issue · 1 comments

the plural forms header is officially optional (see: https://www.gnu.org/software/gettext/manual/html_node/Header-Entry.html) but gets added with an empty line to the header.

This is also true for the other header fields, which are not officially optional but do not even produce warnings when missing (we run a few po files with some header entries for years. only a few like content type and encoding produce actually warnings/errors when not correctly set)

I'm not sure if this is only a "to_s" error and otherwise pretty much irrelevant, but I will post any bugs I find while testing if your parser is good to go for my project.

example file:

# Test single po
# Copyright (c) 2014 Experteer GmbH
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Version 1\n"
"POT-Creation-Date: 2016-11-09 17:12+0100\n"
"PO-Revision-Date: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "hi"
msgstr "hi"

msgcat output:

# Test single po
# Copyright (c) 2014 Experteer GmbH
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Version 1\n"
"POT-Creation-Date: 2016-11-09 17:12+0100\n"
"PO-Revision-Date: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

msgid "hi"
msgstr "hi"

your output:

# Test single po
# Copyright (c) 2014 Experteer GmbH
#
msgid ""
msgstr ""
"Project-Id-Version: Version 1\n"
"POT-Creation-Date: 2016-11-09 17:12+0100\n"
"PO-Revision-Date: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"Plural-Forms: \n"

msgid "hi"
msgstr "hi"

We're now showing a warning and just skip the header fields label if empty.