Search code examples
gettextpoxgettextmsgfmt

msgfmt error when generating .po file with xgettext and msginit


When using the following commands to generate a .po file:

xgettext test.js -o test.pot -L JavaScript --from-code=UTF-8

msginit -i test.pot -o de.po --locale=de

I get the following header:

# Copyright (C) 2021 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# test <[email protected]>, 2021.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-16 11:39+0300\n"
"PO-Revision-Date: 2021-04-16 11:40+0300\n"
"Last-Translator: test <[email protected]>\n"
"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ASCII\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

when checking this file with msgfmt -cv /dev/null de.po I get the following error

msgfmt: /dev/null: warning: PO file header missing or invalid
                   warning: charset conversion will not work
msgfmt: found 1 fatal error

I changed the charset=ASCII to charset=UTF-8 in the file de.po but get the same error. I am using Ubuntu Server 20.04 and gettext-tools version 0.19.8.1


Solution

  • If you call msgfmt -cv /dev/null de.po, then /dev/null is the first input file, which isn't what you intended. But no wonder /dev/null doesn't contain a valid PO header.

    What you probably intended is: msgfmt -cvo /dev/null de.po.

    -o implies that /dev/null is the output file.