Boost翻译:Po文件不工作
boost translate: po file not work
我使用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: messagesn"
"Report-Msgid-Bugs-To: n"
"POT-Creation-Date: 2013-04-26 20:50+0800n"
"PO-Revision-Date: 2013-04-26 21:44+0800n"
"Last-Translator: n"
"Language-Team: LANGUAGE <LL@li.org>n"
"MIME-Version: 1.0n"
"Content-Type: text/plain; charset=UTF-8n"
"Content-Transfer-Encoding: 8bitn"
"X-Generator: Poedit 1.5.5n"
"X-Poedit-SourceCharset: UTF-8n"
#: main.cpp:21
msgid "Hello World"
msgstr "您好"
我也从boost_locale开始,这是我如何使它工作的…
-
首先确保你的。mo文件的命名与你引用的域名完全一致,在本例中是hello.mo
-
将。mo文件放入正确的文件结构中,例如,如果您试图将其翻译为西班牙语,则该文件为。/es_ES/LC_MESSAGES/hello.mo
-
确保像这样实例化全局语言环境,地区:全球(创("es_ES.UTF-8"));
相关文章:
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- 我的文件无法正常工作,无法从C++文件中读取上下文
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- 有没有办法关闭文件? fclose 不能很好地工作
- G++ 在生成文件中使用时停止工作
- 代码作为 C 文件工作,但不作为C++文件,错误:'__builtin_types_compatible_p'未在此范围内声明
- 无法使用 Visual Studio 启动 DirectX 11 可执行文件,生成工作正常
- 使用.cpp文件让 RcppArmadillo 在 Rstudio 中工作
- 读取二进制文件大小的短自上周以来停止工作
- 我的 PowerShell 脚本无法按预期工作(用于编译C++文件)
- 不同文件的类,如何使其工作?
- Makefile在Linux中工作,但在Windows下不起作用,在子目录中找不到文件
- C Visual Studio代码不使用工作区中的单个文件夹编译
- 在循环工作时,首先将两个文件读为向量,但仅次于迭代一次
- 在Qt中使用工作线程将数据写入文件的正确方法是什么?
- OpenCV:文件存储操作员">>"在一个项目中工作,但不在另一个项目中工作(在同一类上)
- 仅一个功能的链接错误.在同一类和CPP文件中具有相似签名的其他函数工作正常
- 程序在我的C++工作区中找不到头文件
- 从工作目录 QtWebEngine 读取文件
- 不完整的参数错误,包括其他.cpp文件中的postgres.cpp工作文件