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.
22 static const char *languages[][2] = {
23 { "de", N_("German") },
24 { "en", N_("English") },
25 { "es", N_("Spanish") },
26 { "fr", N_("French") },
27 { "lv", N_("Latvian") },
28 { "nn", N_("Norwegian Nynorsk") },
31 /*---------------------------------------------------------------------------*/
33 void language_init(const char *domain, const char *locale_dir)
35 setlocale(LC_ALL, "");
36 bindtextdomain(domain, locale_dir);
39 bind_textdomain_codeset(domain, "UTF-8");
42 void language_set(int l)
50 strcpy(e, "LANGUAGE=");
51 strncat(e, languages[l - 1][0], 25 - 9);
56 /* Force to update gettext. */
57 setlocale(LC_ALL, "");
60 int language_count(void)
62 return sizeof (languages) / sizeof (languages[0]);
65 int language_from_code(const char *code)
69 for (i = 0; i < language_count(); i++)
70 if (strcmp(languages[i][0], code) == 0)
76 const char *language_name(int id)
78 return id == 0 ? N_("System Default") : languages[id - 1][1];
82 const char *language_code(int id)
84 return id > 0 ? languages[id - 1][0] : "";
87 /*---------------------------------------------------------------------------*/
89 const char *sgettext(const char *msgid)
91 const char *msgval = gettext(msgid);
95 if ((msgval = strrchr(msgid, '^')))
103 /*---------------------------------------------------------------------------*/