Merged branch utf8.
[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 #include "text.h"
23
24 /*---------------------------------------------------------------------------*/
25
26 void lang_init(const char *domain, const char *default_dir)
27 {
28 #if ENABLE_NLS
29     char *dir = getenv("NEVERBALL_LOCALE");
30
31     setlocale(LC_ALL, "");
32
33     bindtextdomain(domain, dir ? dir : default_dir);
34     bind_textdomain_codeset(domain, "UTF-8");
35     textdomain(domain);
36 #else
37     return;
38 #endif
39 }
40
41 const char *sgettext(const char *msgid)
42 {
43 #if ENABLE_NLS
44     const char *msgval = gettext(msgid);
45 #else
46     const char *msgval = msgid;
47 #endif
48
49     if (msgval == msgid)
50     {
51         if ((msgval = strrchr(msgid, '^')))
52             msgval++;
53         else msgval = msgid;
54     }
55     return msgval;
56 }
57
58 const char *get_local_text(const char *msgid)
59 {
60 #if ENABLE_NLS
61     return text_to_locale(gettext(msgid));
62 #else
63     return msgid;
64 #endif
65 }
66
67 /*---------------------------------------------------------------------------*/