Reset LC_NUMERIC category of locale back to start-up default.
[neverball] / share / lang.c
1 /*
2  * Copyright (C) 2006 Jean Privat
3  * Part of the Neverball Project http://icculus.org/neverball/
4  *
5  * NEVERBALL is  free software; you can redistribute  it and/or modify
6  * it under the  terms of the GNU General  Public License as published
7  * by the Free  Software Foundation; either version 2  of the License,
8  * or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT  ANY  WARRANTY;  without   even  the  implied  warranty  of
12  * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU
13  * General Public License for more details.
14  */
15
16 #include <string.h>
17 #include <locale.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20
21 #include "lang.h"
22
23 /*---------------------------------------------------------------------------*/
24
25 #define DEFAULT_CODESET "UTF-8"
26
27 /*---------------------------------------------------------------------------*/
28
29 void lang_init(const char *domain, const char *default_dir)
30 {
31 #if ENABLE_NLS
32     char *dir = getenv("NEVERBALL_LOCALE");
33
34     setlocale(LC_ALL, "");
35     setlocale(LC_NUMERIC, "C");
36
37     bindtextdomain(domain, dir ? dir : default_dir);
38     bind_textdomain_codeset(domain, DEFAULT_CODESET);
39     textdomain(domain);
40 #else
41     return;
42 #endif
43 }
44
45 const char *sgettext(const char *msgid)
46 {
47 #if ENABLE_NLS
48     const char *msgval = gettext(msgid);
49 #else
50     const char *msgval = msgid;
51 #endif
52
53     if (msgval == msgid)
54     {
55         if ((msgval = strrchr(msgid, '^')))
56             msgval++;
57         else msgval = msgid;
58     }
59     return msgval;
60 }
61
62 const char *get_local_text(const char *msgid)
63 {
64 #if ENABLE_NLS
65     char *msgstr, *domain = textdomain(NULL);
66
67     bind_textdomain_codeset(domain, "");
68     msgstr = gettext(msgid);
69     bind_textdomain_codeset(domain, DEFAULT_CODESET);
70
71     return msgstr;
72 #else
73     return msgid;
74 #endif
75 }
76
77 /*---------------------------------------------------------------------------*/