提升翻译:po文件不起作用

时间:2013-04-26 14:11:53

标签: c++ boost locale translate po

我使用boost :: locale来制作多语言exe,但它不起作用。 exe总是输出“Hello World”。 怎么输出“您好”?

我使用了http://www.boost.org/doc/libs/1_53_0/libs/locale/doc/html/messages_formatting.html

中的示例代码
    #include <boost/locale.hpp>
    #include <iostream>

    using namespace std;
    using namespace boost::locale;

    int main()
    {
        generator gen;

        // Specify location of dictionaries
        gen.add_messages_path(".");
        gen.add_messages_domain("hello");

        // Generate locales and imbue them to iostream
        locale::global(gen(""));
        cout.imbue(locale());

        // Display a message using current system locale
        cout << translate("Hello World") << endl;
    }

制作一个po文件和一个mo文件。 Po文件是:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
msgid ""
msgstr ""
"Project-Id-Version: messages\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-04-26 20:50+0800\n"
"PO-Revision-Date: 2013-04-26 21:44+0800\n"
"Last-Translator: \n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.5.5\n"
"X-Poedit-SourceCharset: UTF-8\n"

#: main.cpp:21
msgid "Hello World"
msgstr "您好"

1 个答案:

答案 0 :(得分:1)

我也是以boost_locale开头的,这就是我如何让它发挥作用......

  1. 首先确保您的.mo文件的名称与您引用的域完全相同,在本例中为hello.mo

  2. 将.mo文件放入正确的文件结构中,例如,如果您尝试翻译为西班牙语,则为./es_ES/LC_MESSAGES/hello.mo

  3. 确保您实例化这样的全局语言环境, 区域设置::全局(根( “es_ES.UTF-8”));

  4. 希望这有帮助。