PO文件头丢失或无效

问题描述 投票:1回答:1

我想加 en_SG 翻译成R包,但我遇到了gettext错误,我没有看到任何源头是什么问题。

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

有输出。

  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.

我到底漏了什么?

r gettext po msgfmt
1个回答
1
投票

PO文件应该有一个 "头",它实际上是一个带有空字符串翻译的条目。它看起来像这样。

# 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"

这个头包含了目录的元信息,例如PO文件的编码,在 Content-Type 头部字段。 你缺少这个头字段。

我不知道你是如何生成文件的。po/R-en_SG.po 但你必须确保它至少包含一个最小的PO头。如有疑问,您必须手动添加。

© www.soinside.com 2019 - 2024. All rights reserved.