Chinaunix

标题: 问个土问题,Return _("XXX");的下划线做何用途 [打印本页]

作者: MaxWu    时间: 2009-05-11 14:55
标题: 问个土问题,Return _("XXX");的下划线做何用途
return _("it is based on your username";

这里的下划线是做什么用的呢?

谢谢.
作者: dreamice    时间: 2009-05-11 15:02
标题: 回复 #1 MaxWu 的帖子
这个是win下面的吧
作者: alexhappy    时间: 2009-05-11 15:13
是不是表示宽字符。。。忘了
作者: MMMIX    时间: 2009-05-11 15:18
原帖由 MaxWu 于 2009-5-11 14:55 发表
return _("it is based on your username");

这里的下划线是做什么用的呢?

那就是个宏,具体什么作用要看它的定义

BTW, 单从语法看,也可以是个函数。不过 _ 通常是个和 gettext 相关的宏。

[ 本帖最后由 MMMIX 于 2009-5-11 16:49 编辑 ]
作者: MaxWu    时间: 2009-05-11 16:09
补充一下, 是Linux下的, cracklib里面的.
我来查一下是不是Macro.
先谢谢各位.
作者: connet    时间: 2009-05-11 16:25

很多 软件 用这个来 国际化
gettext
作者: guhan010    时间: 2009-05-11 16:26
windows下肯定没有的 吧,我从来没用过。
定义宽字符是用T或者L吧。你这个没见过。
作者: daybreakcx    时间: 2009-05-11 16:35
是个宏,功能看定义
作者: MaxWu    时间: 2009-05-11 17:37
  对,gettext,下面这个message可以做解释.

Re: _() Macro
From: Trevor Johnson <trevor jpj net>
To: Andreas Sliwka <goff nef wh uni-dortmund de>
cc: gtk-app-devel-list redhat com
Subject: Re: _() Macro
Date: Sat, 20 Nov 1999 07:26:36 -0500 (EST)
> Hi,

Hi, Andreas.

>   I jsut read the gnome documentation and found in gnomeabout.html the
>   macro _() (it wasnt defined but used). The corresponding text says:
>  >note that the descriptive text is surrounded by the _(). This will have
>  > the text translated to the the user's language at runtime.
>
>  How is this done? Where do I find more information/documentation about this?

If you have GNU gettext, you can read about it on one of the gettext info
pages:

     Many packages use `_' (a simple underline) as a keyword, and write
  `_("Translatable string"' instead of `gettext ("Translatable
  string"'.  Further, the coding rule, from GNU standards, wanting that
  there is a space between the keyword and the opening parenthesis is
  relaxed, in practice, for this particular usage.  So, the textual
  overhead per translatable string is reduced to only three characters:
  the underline and the two parentheses.  However, even if GNU `gettext'
  uses this convention internally, it does not offer it officially.  The
  real, genuine keyword is truly `gettext' indeed.  It is fairly easy for
  those wanting to use `_' instead of `gettext' to declare:

       #include <libintl.h>
       #define _(String) gettext (String)

  instead of merely using `#include <libintl.h>'.

> mfg

Mit freundlichen gruessen.
__
Trevor Johnson




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2