2013-04-26 9 views
1

다국어 exe를 만들기 위해 boost :: locale을 사용했지만 동작하지 않습니다. 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 파일과 모 파일을 확인하십시오. 포 파일은 다음과 같습니다도 여기 boost_locale와

# 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

임 시작이 내가 그것을 작동하게하는 방법입니다 ...

  1. 먼저 확인하십시오 .mo 파일을 도메인 사용자 다스 려 정확히 이름 에,이 경우 hello.mo

  2. 당신이 스페인어로 번역하려고하는 경우, 예를 들어, 올바른 파일 구조로 .mo 파일을 넣어이는 것 ./es_ES/LC_MESSAGES/hello.mo

  3. 다음과 같이 전역 로캘을 인스턴스화해야합니다. locale :: global (gen ("es_ES.UTF-8"));

희망이 있습니다.

+0

감사합니다. 나는 그것을 풀었고, 나는 cppcms의 소스 코드를 보았다. – Alberl