- 论坛徽章:
- 0
|
- [root@localhost gettext]# myriconv INSTRUCTION
- 1, 在C程序中include libintl.h和locale.h两个头文件;定义某种宏,来代替每次在程序中使用gettext;
- 2, 按照C程序中bindtextdomain的第二个参数指定的目录,say A,在A/下建立zh_CN,再在zh_CN/下建立
- LC_MESSAGES/目录;
- 3, xgettext -a 你的程序.c,这时我们看到生成了messages.po文件;
- 4, 编辑messages.po文件,将CHARSET改为UTF-8, 翻译需要翻译的那些串;
- 5, 运行msgfmt messages.po -o 你的程序.mo,把mo文件拷贝到A/zh_CN/LC_MESSAGES/目录下。注意,mo文
- 件的名字,必须跟可执行文件的名字除扩展名部分,完全一样。否则gettext不起作用。
- 好了,可以运行了。
- 如果有多个文件的话,情况有点复杂。msgmerge和msgfmt的提取合并功能根本不好用,得在xgettext时生
- 成一个单一的.po文件。
- #xgettext -a hello.c main.c -o hello.po
- 然后修改hello.po文件,msgfmt hello.po -o hello.mo,再拷贝到相关目录下。
- [root@localhost gettext]# cat hello.c
- #include <stdio.h>
- #include <libintl.h>
- #include <locale.h>
- #include "main.h"
- #define PACKAGE "hello"
- #define LOCALEDIR "./locale/"
- #define _(s) gettext(s)
- #define N_(s) s
- int main(int argc, char** argv)
- {
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
- printf(_("hello world\n"));
- f();
- return 0;
- }
复制代码 |
|