2013-04-26 81 views
1

我用boost :: locale製作了一個多語言exe文件,但它不起作用。 該exe文件總是輸出「Hello World」。 如何輸出「您好」?boost翻譯:po文件不起作用

我使用的示例代碼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 protected]>, 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 <[email protected]>\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

林年初boost_locale過,這是我如何使它工作...

  1. 首先確保你的.mo文件正是命名爲域的闖民宅到,在這種情況下hello.mo

  2. 把文件的.mo到正確的文件結構,例如,如果你想翻譯成西班牙語,這將是./es_ES/LC_MESSAGES/hello.mo

  3. 請確保你實例化了這樣的全局語言環境, locale :: global(gen(「es_ES.UTF-8」));

希望這會有所幫助。

+0

謝謝,你是對的。 我已經解決了它,我看了cppcms的源代碼。 – Alberl 2013-06-08 12:23:09