提交 f6876e10 编写于 作者: E Eric Blake 提交者: Jim Meyering

virsh: fix existing N_ uses

It is a bad idea to call gettext on an already-translated
string.  In cases where a string must be translated separately
from where it is exposed to xgettext, the gettext manual
recommends the idiom of N_() wrapping gettext_noop for
marking the string.

* src/internal.h (N_): Fix definition to match gettext manual.
* tools/virsh.c: (cmdHelp, cmdList, cmdDomstate, cmdDominfo)
(cmdVcpuinfo, vshUsage): Replace incorrect use of N_ with _.
(vshCmddefHelp): Likewise.  Mark C format strings appropriately.
上级 d1c75416
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
#endif #endif
#define _(str) dgettext(GETTEXT_PACKAGE, (str)) #define _(str) dgettext(GETTEXT_PACKAGE, (str))
#define N_(str) dgettext(GETTEXT_PACKAGE, (str)) #define N_(str) str
/* String equality tests, suggested by Jim Meyering. */ /* String equality tests, suggested by Jim Meyering. */
#define STREQ(a,b) (strcmp(a,b) == 0) #define STREQ(a,b) (strcmp(a,b) == 0)
......
...@@ -429,7 +429,7 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd) ...@@ -429,7 +429,7 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%s", _("Commands:\n\n")); vshPrint(ctl, "%s", _("Commands:\n\n"));
for (def = commands; def->name; def++) for (def = commands; def->name; def++)
vshPrint(ctl, " %-15s %s\n", def->name, vshPrint(ctl, " %-15s %s\n", def->name,
N_(vshCmddefGetInfo(def, "help"))); _(vshCmddefGetInfo(def, "help")));
return TRUE; return TRUE;
} }
return vshCmddefHelp(ctl, cmdname); return vshCmddefHelp(ctl, cmdname);
...@@ -725,7 +725,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -725,7 +725,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (virDomainGetInfo(dom, &info) < 0) if (virDomainGetInfo(dom, &info) < 0)
state = _("no state"); state = _("no state");
else else
state = N_(vshDomainStateToString(info.state)); state = _(vshDomainStateToString(info.state));
vshPrint(ctl, "%3d %-20s %s\n", vshPrint(ctl, "%3d %-20s %s\n",
virDomainGetID(dom), virDomainGetID(dom),
...@@ -747,7 +747,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED) ...@@ -747,7 +747,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (virDomainGetInfo(dom, &info) < 0) if (virDomainGetInfo(dom, &info) < 0)
state = _("no state"); state = _("no state");
else else
state = N_(vshDomainStateToString(info.state)); state = _(vshDomainStateToString(info.state));
vshPrint(ctl, "%3s %-20s %s\n", "-", names[i], state); vshPrint(ctl, "%3s %-20s %s\n", "-", names[i], state);
...@@ -788,7 +788,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd) ...@@ -788,7 +788,7 @@ cmdDomstate(vshControl *ctl, const vshCmd *cmd)
if (virDomainGetInfo(dom, &info) == 0) if (virDomainGetInfo(dom, &info) == 0)
vshPrint(ctl, "%s\n", vshPrint(ctl, "%s\n",
N_(vshDomainStateToString(info.state))); _(vshDomainStateToString(info.state)));
else else
ret = FALSE; ret = FALSE;
...@@ -1761,7 +1761,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd) ...@@ -1761,7 +1761,7 @@ cmdDominfo(vshControl *ctl, const vshCmd *cmd)
if (virDomainGetInfo(dom, &info) == 0) { if (virDomainGetInfo(dom, &info) == 0) {
vshPrint(ctl, "%-15s %s\n", _("State:"), vshPrint(ctl, "%-15s %s\n", _("State:"),
N_(vshDomainStateToString(info.state))); _(vshDomainStateToString(info.state)));
vshPrint(ctl, "%-15s %d\n", _("CPU(s):"), info.nrVirtCpu); vshPrint(ctl, "%-15s %d\n", _("CPU(s):"), info.nrVirtCpu);
...@@ -2040,7 +2040,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd) ...@@ -2040,7 +2040,7 @@ cmdVcpuinfo(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "%-15s %d\n", _("VCPU:"), n); vshPrint(ctl, "%-15s %d\n", _("VCPU:"), n);
vshPrint(ctl, "%-15s %d\n", _("CPU:"), cpuinfo[n].cpu); vshPrint(ctl, "%-15s %d\n", _("CPU:"), cpuinfo[n].cpu);
vshPrint(ctl, "%-15s %s\n", _("State:"), vshPrint(ctl, "%-15s %s\n", _("State:"),
N_(vshDomainVcpuStateToString(cpuinfo[n].state))); _(vshDomainVcpuStateToString(cpuinfo[n].state)));
if (cpuinfo[n].cpuTime != 0) { if (cpuinfo[n].cpuTime != 0) {
double cpuUsed = cpuinfo[n].cpuTime; double cpuUsed = cpuinfo[n].cpuTime;
...@@ -7869,8 +7869,8 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname) ...@@ -7869,8 +7869,8 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)
vshError(ctl, _("command '%s' doesn't exist"), cmdname); vshError(ctl, _("command '%s' doesn't exist"), cmdname);
return FALSE; return FALSE;
} else { } else {
const char *desc = N_(vshCmddefGetInfo(def, "desc")); const char *desc = _(vshCmddefGetInfo(def, "desc"));
const char *help = N_(vshCmddefGetInfo(def, "help")); const char *help = _(vshCmddefGetInfo(def, "help"));
char buf[256]; char buf[256];
fputs(_(" NAME\n"), stdout); fputs(_(" NAME\n"), stdout);
...@@ -7885,15 +7885,17 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname) ...@@ -7885,15 +7885,17 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)
if (opt->type == VSH_OT_BOOL) if (opt->type == VSH_OT_BOOL)
fmt = "[--%s]"; fmt = "[--%s]";
else if (opt->type == VSH_OT_INT) else if (opt->type == VSH_OT_INT)
fmt = N_("[--%s <number>]"); /* xgettext:c-format */
fmt = _("[--%s <number>]");
else if (opt->type == VSH_OT_STRING) else if (opt->type == VSH_OT_STRING)
fmt = N_("[--%s <string>]"); /* xgettext:c-format */
fmt = _("[--%s <string>]");
else if (opt->type == VSH_OT_DATA) else if (opt->type == VSH_OT_DATA)
fmt = ((opt->flag & VSH_OFLAG_REQ) ? "<%s>" : "[<%s>]"); fmt = ((opt->flag & VSH_OFLAG_REQ) ? "<%s>" : "[<%s>]");
else else
assert(0); assert(0);
fputc(' ', stdout); fputc(' ', stdout);
fprintf(stdout, _(fmt), opt->name); fprintf(stdout, fmt, opt->name);
} }
} }
fputc('\n', stdout); fputc('\n', stdout);
...@@ -7917,7 +7919,7 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname) ...@@ -7917,7 +7919,7 @@ vshCmddefHelp(vshControl *ctl, const char *cmdname)
else if (opt->type == VSH_OT_DATA) else if (opt->type == VSH_OT_DATA)
snprintf(buf, sizeof(buf), "<%s>", opt->name); snprintf(buf, sizeof(buf), "<%s>", opt->name);
fprintf(stdout, " %-15s %s\n", buf, N_(opt->help)); fprintf(stdout, " %-15s %s\n", buf, _(opt->help));
} }
} }
fputc('\n', stdout); fputc('\n', stdout);
...@@ -9148,8 +9150,7 @@ vshUsage(void) ...@@ -9148,8 +9150,7 @@ vshUsage(void)
for (cmd = commands; cmd->name; cmd++) for (cmd = commands; cmd->name; cmd++)
fprintf(stdout, fprintf(stdout,
" %-15s %s\n", cmd->name, N_(vshCmddefGetInfo(cmd, " %-15s %s\n", cmd->name, _(vshCmddefGetInfo(cmd, "help")));
"help")));
fprintf(stdout, "%s", fprintf(stdout, "%s",
_("\n (specify help <command> for details about the command)\n\n")); _("\n (specify help <command> for details about the command)\n\n"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册