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"
26 /*---------------------------------------------------------------------------*/
28 #define DEFAULT_CODESET "UTF-8"
30 /*---------------------------------------------------------------------------*/
32 void lang_init(const char *domain, const char *default_dir)
35 char *dir = getenv("NEVERBALL_LOCALE");
38 dir = path_resolve(config_exec_path, default_dir);
42 if (!setlocale(LC_ALL, ""))
44 fprintf(stderr, "Failed to set LC_ALL to native locale: %s\n",
45 errno ? strerror(errno) : "Unknown error");
48 /* The C locale is guaranteed (sort of) to be available. */
50 setlocale(LC_NUMERIC, "C");
52 bindtextdomain(domain, dir);
53 bind_textdomain_codeset(domain, DEFAULT_CODESET);
60 const char *sgettext(const char *msgid)
63 const char *msgval = gettext(msgid);
65 const char *msgval = msgid;
70 if ((msgval = strrchr(msgid, '^')))
77 const char *get_local_text(const char *msgid)
80 char *msgstr, *domain = textdomain(NULL);
82 bind_textdomain_codeset(domain, "");
83 msgstr = gettext(msgid);
84 bind_textdomain_codeset(domain, DEFAULT_CODESET);
92 /*---------------------------------------------------------------------------*/