1.准备软件.下载从mingw官方
gettext-0.17-1-mingw32-dev.tar.lzma
libiconv-1.13.1-1-mingw32-dev.tar.lzma
libintl-0.17-1-mingw32-dll-8.tar.lzma
libgettextpo-0.17-1-mingw32-dll-0.tar.lzma
libasprintf-0.17-1-mingw32-dll-0.tar.lzma
libcharset-1.13.1-1-mingw32-dll-1.tar.lzma
poedit
解压到mingw目录下bin,lib,include,share等等
2.新建jian_gettext.c
Code: Select all
#include <stdio.h>
#include <locale.h>
#include <libintl.h>
#define _(S) gettext(S)
#define PACKAGE "jian_gettext"
int main(int argc, char **argv)
{
setlocale(LC_ALL,"");
bindtextdomain(PACKAGE, "locale");
textdomain(PACKAGE);
printf(_("Hello,GetText!\n"));
return 0;
}
gcc -o jian_gettext jian_gettext.c
报错
jian_gettext.c:(.text+0x36): undefined reference to `_libintl_bindtextdomain'
jian_gettext.c:(.text+0x46): undefined reference to `_libintl_textdomain'
jian_gettext.c:(.text+0x56): undef ined reference to `_libintl_gettext'
jian_gettext.c:(.text+0x62): undefined reference to `___printf__'
collect2: ld returned 1 exit status
原因是mingw没找到intl
gcc -o jian_gettext jian_gettext.c -intl
网上说增加gcc 的lib路径就可以了
注意:在ECERE IDE中如何实现呢,还不知道
好了程序可以运行了.
我们来做翻译工作吧
Code: Select all
xgettext -o jian_gettext.po jian_gettext.c
修改
"Content-Type: text/plain; charset=CHARSET\n"
为
"Content-Type: text/plain; charset=UTF-8\n"
修改
msgstr ""
为
msgstr "你好,GetText!\n"
保存为UTF-8格式文件
打开poedit 打开jian_gettext.po保存后,自动生成jian_gettext.mo文件
将.mo文件拷贝到jian_gettext所在的 locale\zh_CN\LC_MESSAGES文件下
重新生成一次
gcc -o jian_gettext jian_gettext.c -lintl
好了
运行一下jian_gettext
jian_gettext
你好,GetText!
第一次运行的比较慢,再运行就快了.