【问题标题】:msgfmt "invalid multibyte sequence" error on a Polish text波兰语文本上的 msgfmt“无效多字节序列”错误
【发布时间】:2010-11-08 04:25:50
【问题描述】:

使用Complete C++ i18n gettext() “hello world” example,我将语言环境从“es_MX”更改为“pl_PL”,并将文本从“hello, world!”更改为到“输入无效。请输入至少 20 个字符长的字符串。”。波兰语翻译包含几个字符,这些字符会导致 msgfmt 中出现“无效的多字节序列”错误,“łąźó”。翻译后的文本是从网页复制而来的。

我认为 utf8 是问题所在。如果是,应该用什么代替?

cat >plt.cxx <<EOF
// plt.cxx
#include <libintl.h>
#include <locale.h>
#include <iostream>
int main (){
    setlocale(LC_ALL, "");
    bindtextdomain("plt", ".");
    textdomain( "plt");
    std::cout << gettext("Invalid input. Enter a string at least 20 characters long.") << std::endl;
}
EOF
g++ -o plt plt.cxx
xgettext --package-name plt --package-version 1.2 --default-domain plt --output plt.pot plt.cxx 
msginit --no-translator --locale pl_PL --output-file plt_polish.po --input plt.pot
sed --in-place plt_polish.po --expression='/#: /,$ s/""/"Nieprawidłowo wprowadzone dane. Wprowadź ciąg przynajmniej 20 znaków."/'
mkdir --parents ./pl_PL.utf8/LC_MESSAGES
msgfmt --check --verbose --output-file ./pl_PL.utf8/LC_MESSAGES/plt.mo plt_polish.po
LANGUAGE=pl_PL.utf8 ./plt

【问题讨论】:

    标签: linux internationalization gettext


    【解决方案1】:

    编辑 plt_polish.po 并将 Content-Type 行更改为“Content-Type: text/plain; charset=UTF-8\n”(将字符集从 ASCII 更改为 UTF-8)

    【讨论】:

    • 在 msginit 之前添加“sed --in-place plt.pot --expression='s/CHARSET/UTF-8/'”。
    • 我建议将编辑应用到 .po 文件,而不是 pot 文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多