Skip to content

Commit 6578483

Browse files
avargitster
authored andcommitted
i18n: add no-op _() and N_() wrappers
The _ function is for translating strings into the user's chosen language. The N_ macro just marks translatable strings for the xgettext(1) tool without translating them; it is intended for use in contexts where a function call cannot be used. So, for example: fprintf(stderr, _("Expansion of alias '%s' failed; " "'%s' is not a git command\n"), cmd, argv[0]); and const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = { /* ERROR_WOULD_OVERWRITE */ N_("Entry '%s' would be overwritten by merge. Cannot merge."), [...] Define such _ and N_ in a new gettext.h and include it in cache.h, so they can be used everywhere. Each just returns its argument for now. _ is a function rather than a macro like N_ to avoid the temptation to use _("foo") as a string literal (which would be a compile-time error once _(s) expands to an expression for the translation of s). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 098d0e0 commit 6578483

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ LIB_H += diff.h
515515
LIB_H += dir.h
516516
LIB_H += exec_cmd.h
517517
LIB_H += fsck.h
518+
LIB_H += gettext.h
518519
LIB_H += git-compat-util.h
519520
LIB_H += graph.h
520521
LIB_H += grep.h

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "strbuf.h"
66
#include "hash.h"
77
#include "advice.h"
8+
#include "gettext.h"
89

910
#include SHA1_HEADER
1011
#ifndef git_SHA_CTX

gettext.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2010-2011 Ævar Arnfjörð Bjarmason
3+
*
4+
* This is a skeleton no-op implementation of gettext for Git.
5+
* You can replace it with something that uses libintl.h and wraps
6+
* gettext() to try out the translations.
7+
*/
8+
9+
#ifndef GETTEXT_H
10+
#define GETTEXT_H
11+
12+
#ifdef _
13+
#error "namespace conflict: '_' is pre-defined?"
14+
#endif
15+
16+
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
17+
18+
static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
19+
{
20+
return msgid;
21+
}
22+
23+
/* Mark msgid for translation but do not translate it. */
24+
#define N_(msgid) (msgid)
25+
26+
#endif

0 commit comments

Comments
 (0)