Skip to content

Commit 93f7d91

Browse files
peffgitster
authored andcommitted
gettext.c: move get_preferred_languages() from http.c
Calling setlocale(LC_MESSAGES, ...) directly from http.c, without including <locale.h>, was causing compilation warnings. Move the helper function to gettext.c that already includes the header and where locale-related issues are handled. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f18604b commit 93f7d91

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

gettext.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,31 @@
1818
# endif
1919
#endif
2020

21+
/*
22+
* Guess the user's preferred languages from the value in LANGUAGE environment
23+
* variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
24+
*
25+
* The result can be a colon-separated list like "ko:ja:en".
26+
*/
27+
const char *get_preferred_languages(void)
28+
{
29+
const char *retval;
30+
31+
retval = getenv("LANGUAGE");
32+
if (retval && *retval)
33+
return retval;
34+
35+
#ifndef NO_GETTEXT
36+
retval = setlocale(LC_MESSAGES, NULL);
37+
if (retval && *retval &&
38+
strcmp(retval, "C") &&
39+
strcmp(retval, "POSIX"))
40+
return retval;
41+
#endif
42+
43+
return NULL;
44+
}
45+
2146
#ifdef GETTEXT_POISON
2247
int use_gettext_poison(void)
2348
{

gettext.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)
6565
/* Mark msgid for translation but do not translate it. */
6666
#define N_(msgid) msgid
6767

68+
const char *get_preferred_languages(void);
69+
6870
#endif

http.c

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "credential.h"
99
#include "version.h"
1010
#include "pkt-line.h"
11+
#include "gettext.h"
1112

1213
int active_requests;
1314
int http_is_verbose;
@@ -991,31 +992,6 @@ static void extract_content_type(struct strbuf *raw, struct strbuf *type,
991992
strbuf_addstr(charset, "ISO-8859-1");
992993
}
993994

994-
/*
995-
* Guess the user's preferred languages from the value in LANGUAGE environment
996-
* variable and LC_MESSAGES locale category if NO_GETTEXT is not defined.
997-
*
998-
* The result can be a colon-separated list like "ko:ja:en".
999-
*/
1000-
static const char *get_preferred_languages(void)
1001-
{
1002-
const char *retval;
1003-
1004-
retval = getenv("LANGUAGE");
1005-
if (retval && *retval)
1006-
return retval;
1007-
1008-
#ifndef NO_GETTEXT
1009-
retval = setlocale(LC_MESSAGES, NULL);
1010-
if (retval && *retval &&
1011-
strcmp(retval, "C") &&
1012-
strcmp(retval, "POSIX"))
1013-
return retval;
1014-
#endif
1015-
1016-
return NULL;
1017-
}
1018-
1019995
static void write_accept_language(struct strbuf *buf)
1020996
{
1021997
/*

0 commit comments

Comments
 (0)