Made internationalisation optional; to compile the game without I18N,
[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 <stdlib.h>
18 #include <locale.h>
19
20 #include "lang.h"
21
22 /*---------------------------------------------------------------------------*/
23
24 void lang_init(const char *domain, const char *default_dir)
25 {
26 #ifndef DISABLE_NLS
27     char *dir = getenv("NEVERBALL_LOCALE");
28
29     setlocale(LC_ALL, "");
30
31     bindtextdomain(domain, dir ? dir : default_dir);
32     bind_textdomain_codeset(domain, "UTF-8");
33     textdomain(domain);
34 #endif
35 }
36
37 const char *sgettext(const char *msgid)
38 {
39 #ifndef DISABLE_NLS
40     const char *msgval = gettext(msgid);
41 #else
42     const char *msgval = msgid;
43 #endif
44
45     if (msgval == msgid)
46     {
47         if ((msgval = strrchr(msgid, '^')))
48             msgval++;
49         else msgval = msgid;
50     }
51     return msgval;
52 }
53
54 /*---------------------------------------------------------------------------*/