如何在Linux C/C ++程序中支持多种语言? [英] How to support multiple language in a Linux C/C++ program?
问题描述
例如,在这个最简单的hello world程序中:
For example, in this simplest hello world program:
#include <iostream>
int main()
{
std::cout<<"Hello World!"<<std::endl;
return 0;
}
我想看看法语,如果用户的环境LANG
设置为fr_FR
,它可能看起来像:
I'd like to see French if user's environment LANG
is set to fr_FR
, it might looks like:
$ ./a.out
Hello World!
$ LANG=fr_FR.utf8
$ ./a.out
Bonjour tout le monde!
是否有关于如何在Linux中进行归档的指南?
Is there a guideline of how to archieve this in Linux?
推荐答案
关键是使用资源"(一种语言,配置为在运行时读取)与硬编码字符串. Qt和GTK +之类的GUI框架使此操作(相对)变得容易.
The key is to use "resources" (one per-language, configured to be read at runtime) vs. hard-coding strings. GUI frameworks like Qt and GTK+ make this (relatively) easy.
这是GTK +使用的Pango库的链接(但不是GTK +的专有):
Here's a link to the Pango" library used by GTK+ (but not, emphatically, exclusive to GTK+):
这是使用Pango的教程:
Here's a tutorial on using Pango:
这是有关"gettext()"的教程(我相信Pango会使用该教程):
And here's a tutorial on "gettext()" (which, I believe, Pango uses):
这篇关于如何在Linux C/C ++程序中支持多种语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!