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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 25, 2015 at 22:04 UTC 93f7d9108a0edf808e1e3bbcdbe6078310c22f9e
3 files changed +28 -25
gettext.c
+25
@@ -18,6 +18,31 @@
18 # endif
19 #endif
20
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 +
46 #ifdef GETTEXT_POISON
47 int use_gettext_poison(void)
48 {
gettext.h
+2
@@ -65,4 +65,6 @@ const char *Q_(const char *msgid, const char *plu, unsigned long n)
65 /* Mark msgid for translation but do not translate it. */
66 #define N_(msgid) msgid
67
68 +const char *get_preferred_languages(void);
69 +
70 #endif
http.c
+1 -25
@@ -8,6 +8,7 @@
8 #include "credential.h"
9 #include "version.h"
10 #include "pkt-line.h"
11 +#include "gettext.h"
12
13 int active_requests;
14 int http_is_verbose;
@@ -991,31 +992,6 @@ static void extract_content_type(struct strbuf *raw, struct strbuf *type,
992 strbuf_addstr(charset, "ISO-8859-1");
993 }
994
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 -
995 static void write_accept_language(struct strbuf *buf)
996 {
997 /*