免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1833 | 回复: 9
打印 上一主题 下一主题

printf(_("AAA") );中的_(..)是什么意思? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-04-12 10:17 |只看该作者 |倒序浏览
那位指点一二,多谢

论坛徽章:
0
2 [报告]
发表于 2006-04-12 10:33 |只看该作者
GNU gettext的语法, 它根据当前locale转换不同的输出

论坛徽章:
0
3 [报告]
发表于 2006-04-12 10:34 |只看该作者
多谢。

论坛徽章:
0
4 [报告]
发表于 2006-04-12 10:35 |只看该作者

  1. [root@localhost gettext]# myriconv INSTRUCTION
  2. 1, 在C程序中include libintl.h和locale.h两个头文件;定义某种宏,来代替每次在程序中使用gettext;
  3. 2, 按照C程序中bindtextdomain的第二个参数指定的目录,say A,在A/下建立zh_CN,再在zh_CN/下建立
  4.         LC_MESSAGES/目录;
  5. 3, xgettext -a 你的程序.c,这时我们看到生成了messages.po文件;
  6. 4, 编辑messages.po文件,将CHARSET改为UTF-8, 翻译需要翻译的那些串;
  7. 5, 运行msgfmt messages.po -o 你的程序.mo,把mo文件拷贝到A/zh_CN/LC_MESSAGES/目录下。注意,mo文
  8.         件的名字,必须跟可执行文件的名字除扩展名部分,完全一样。否则gettext不起作用。

  9. 好了,可以运行了。


  10. 如果有多个文件的话,情况有点复杂。msgmerge和msgfmt的提取合并功能根本不好用,得在xgettext时生
  11. 成一个单一的.po文件。
  12.         #xgettext -a hello.c main.c -o hello.po
  13. 然后修改hello.po文件,msgfmt hello.po -o hello.mo,再拷贝到相关目录下。

  14. [root@localhost gettext]# cat hello.c
  15. #include <stdio.h>
  16. #include <libintl.h>
  17. #include <locale.h>
  18. #include "main.h"

  19. #define PACKAGE "hello"
  20. #define LOCALEDIR "./locale/"
  21. #define _(s) gettext(s)
  22. #define N_(s) s

  23. int main(int argc, char** argv)
  24. {
  25.         setlocale(LC_ALL, "");
  26.         bindtextdomain(PACKAGE, LOCALEDIR);
  27.         textdomain(PACKAGE);


  28.         printf(_("hello world\n"));
  29.         f();

  30.         return 0;
  31. }
复制代码

论坛徽章:
0
5 [报告]
发表于 2006-04-12 10:41 |只看该作者
试了一下
连接不通过
说是找不到'_'这个函数
??

原来如彼
知道了

[ 本帖最后由 bleem1998 于 2006-4-12 10:43 编辑 ]

论坛徽章:
0
6 [报告]
发表于 2006-04-12 10:43 |只看该作者
原帖由 bleem1998 于 2006-4-12 10:41 发表
试了一下
连接不通过
说是找不到'_'这个函数
??

那是个宏定义, #define _(s) gettext(s)

论坛徽章:
0
7 [报告]
发表于 2006-04-12 11:50 |只看该作者
  1. cat>hello.c<<end
  2. #include <stdio.h>
  3. #include <libintl.h>
  4. #include <locale.h>
  5. [color=Red]//#include "main.h"[/color]

  6. #define PACKAGE "hello"
  7. #define LOCALEDIR "./locale/"
  8. #define _(s) gettext(s)
  9. #define N_(s) s

  10. int main(int argc, char** argv)
  11. {
  12.         setlocale(LC_ALL, "");
  13.         bindtextdomain(PACKAGE, LOCALEDIR);
  14.         textdomain(PACKAGE);


  15.         printf(_("hello world\n"));
  16.       [color=Red]//f();[/color]

  17.         return 0;
  18. }
  19. end

复制代码




可以运行,不过没看懂

论坛徽章:
0
8 [报告]
发表于 2006-04-12 12:28 |只看该作者
原帖由 albcamus 于 2006-4-12 10:35 发表
[code]
[root@localhost gettext]# myriconv INSTRUCTION
1, 在C程序中include libintl.h和locale.h两个头文件;定义某种宏,来代替每次在程序中使用gettext;
2, 按照C程序中bindtextdomain的第二个参数指定的 ...



迷糊中,没看懂

论坛徽章:
0
9 [报告]
发表于 2006-04-12 12:31 |只看该作者
原帖由 net_robber 于 2006-4-12 11:50 发表
[code]cat>hello.c<<end
#include <stdio.h>
#include <libintl.h>
#include <locale.h>
//#include "main.h"

#define PACKAGE "hello&quo ...


不好意思, 那个是我为了测试多个源文件时应该怎样i18n, 写了两个*.c, hello.c和main.c。

不贴了。主要是其中的一些跟gettext有关的东西, 其他的不足道

论坛徽章:
0
10 [报告]
发表于 2006-04-12 12:38 |只看该作者
也许我暂时还研究不了这些,i18n到底怎么玩,我还都没有完全搞明白

另外,不修改i18n,单独修改每个用户的默认语言在哪里搞,给讲一下好么??
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP