PO file header missing or invalid

1.4k Views Asked by At

I'm trying to add en_SG translations to an R package, but I'm met with a gettext error and I haven't seen any source on what's the issue:

list.files('po')
# [1] "R-myPkg.pot"
# [2] "R-en_SG.po"
tools::update_pkg_po('.')

has output:

  R-en_SG:. done.
msgfmt: po/R-en_SG.po: warning: PO file header missing or invalid
                       warning: charset conversion will not work
msgfmt: found 1 fatal error
Warning in tools::update_pkg_po(".") :
  running msgfmt on R-en_SG.po failed
  R-en@quot:
2 translated messages.

What exactly am I missing?

2

There are 2 best solutions below

2
On BEST ANSWER

PO files should have a "header" which is really an entry with a translation for the empty string. It looks like this:

# German translations for qgoda package.
# Copyright (C) 2018 Guido Flohr <http://www.guido-flohr.net>
# This file is distributed under the same license as the qgoda package.
# Guido Flohr <[email protected]>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: qgoda 0.1.1\n"
"Report-Msgid-Bugs-To: Guido Flohr <[email protected]>\n"
"POT-Creation-Date: 2018-05-16 20:36+0300\n"
"PO-Revision-Date: 2018-05-16 20:37+0300\n"
"Last-Translator: Guido Flohr <[email protected]>\n"
"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

This header contains meta information for the catalog, for example the encoding of the PO file in the Content-Type header field. You are missing this header field.

I don't know how you generate the file po/R-en_SG.po but you have to ensure that it contains at least a minimal PO header. In doubt, you have to add it manually.

0
On

Just a note really. If using Poedit then saving the .po file will create the header and then you can compile without error