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.
16 /* The following declaration is needed to have the putenv function
17 * http://www.gnu.org/software/libc/manual/html_node/Environment-Access.html
20 #define _XOPEN_SOURCE 1
27 const char *sgettext(const char *msgid)
29 const char *msgval = gettext(msgid);
33 if ((msgval = strrchr(msgid, '^')))
41 /*---------------------------------------------------------------------------*/
45 const char *language_names[] = {
51 const char *language_codes[] = {"en", "fr", "de", "lv"};
53 /*---------------------------------------------------------------------------*/
55 void language_init(const char *domain, const char *locale_dir)
57 setlocale(LC_ALL, "");
58 bindtextdomain(domain, locale_dir);
60 bind_textdomain_codeset(domain, "UTF-8");
63 void language_set(int l)
67 /* remove the LANGUAGE env variable */
74 /* set the LANGUAGE env variable */
75 strcpy(e, "LANGUAGE=");
76 strncat(e, language_codes[l - 1], 25 - 9);
80 /* Force to update gettext. */
81 setlocale(LC_ALL, "");
84 int language_count(void)
89 int language_from_code(const char *code)
93 for (i = 0; i < LANG_NUMBER; i++)
94 if (strcmp(language_codes[i], code) == 0)
100 const char *language_get_name(int id)
102 return id == 0 ? _("System Default") : language_names[id - 1];
106 const char *language_get_code(int id)
108 return id > 0 ? language_codes[id - 1] : "";