2 * Copyright (C) 2006 Jean Privat
3 * Part of the Neverball Project http://icculus.org/neverball/
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.
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.
24 #include "base_config.h"
27 /*---------------------------------------------------------------------------*/
29 #define DEFAULT_CODESET "UTF-8"
31 /*---------------------------------------------------------------------------*/
33 void lang_init(const char *domain)
36 char *dir = strdup(getenv("NEVERBALL_LOCALE"));
40 if (path_is_abs(CONFIG_LOCALE))
41 dir = strdup(CONFIG_LOCALE);
43 dir = concat_string(fs_base_dir(), "/", CONFIG_LOCALE, NULL);
48 if (!setlocale(LC_ALL, ""))
50 fprintf(stderr, "Failed to set LC_ALL to native locale: %s\n",
51 errno ? strerror(errno) : "Unknown error");
54 /* The C locale is guaranteed (sort of) to be available. */
56 setlocale(LC_NUMERIC, "C");
58 bindtextdomain(domain, dir);
59 bind_textdomain_codeset(domain, DEFAULT_CODESET);
68 const char *sgettext(const char *msgid)
71 const char *msgval = gettext(msgid);
73 const char *msgval = msgid;
78 if ((msgval = strrchr(msgid, '^')))
85 const char *get_local_text(const char *msgid)
88 char *msgstr, *domain = textdomain(NULL);
90 bind_textdomain_codeset(domain, "");
91 msgstr = gettext(msgid);
92 bind_textdomain_codeset(domain, DEFAULT_CODESET);
100 /*---------------------------------------------------------------------------*/