X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=share%2Fi18n.c;h=7d6fd9201b85b4fd058f93c63716fcb7dd0a3e25;hb=90baa3b05af80b5996bb2eecebd58ca2ceb53acf;hp=5c8f1c4a1cf9714057b86b3fc6ecbe26fe76f237;hpb=727e559f47d50bc8ebacb574605f0f8962f0f583;p=neverball diff --git a/share/i18n.c b/share/i18n.c index 5c8f1c4..7d6fd92 100644 --- a/share/i18n.c +++ b/share/i18n.c @@ -1,26 +1,59 @@ +/* + * Copyright (C) 2006 Jean Privat + * Part of the Neverball Project http://icculus.org/neverball/ + * + * NEVERBALL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, + * or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + */ + +/* The following declaration is needed to have the putenv function + * http://www.gnu.org/software/libc/manual/html_node/Environment-Access.html + */ + +#define _XOPEN_SOURCE 1 #include #include #include #include "i18n.h" - -const char * gettextdbg(const char * c) +const char *sgettext(const char *msgid) { - char * c2 = gettext(c); - if(strcmp(c, c2)); - return c; + const char *msgval = gettext(msgid); + + if (msgval == msgid) + { + if ((msgval = strrchr(msgid, '^'))) + msgval++; + else + msgval = msgid; + } + return msgval; } /*---------------------------------------------------------------------------*/ -#define LANG_NUMBER 4 -const char * language_names[] = {N_("English"), N_("French"), N_("German"), N_("Latvian")}; -const char * language_codes[] = {"en", "fr", "de", "lv"}; +#define LANG_NUMBER 5 + +const char *language_names[] = { + N_("English"), + N_("French"), + N_("German"), + N_("Latvian"), + N_("Spanish"), +}; +const char *language_codes[] = {"en", "fr", "de", "lv", "es"}; /*---------------------------------------------------------------------------*/ -void language_init(const char * domain, const char * locale_dir) +void language_init(const char *domain, const char *locale_dir) { setlocale(LC_ALL, ""); bindtextdomain(domain, locale_dir); @@ -32,18 +65,21 @@ void language_set(int l) { if (l == 0) { - /* remove the LANGUAGE env variable */ - putenv("LANGUAGE"); + /* remove the LANGUAGE env variable */ + putenv("LANGUAGE"); } else { static char e[25]; - /* set the LANGUAGE env variable */ - strcpy(e, "LANGUAGE="); - strncat(e, language_codes[l-1], 25-9); - putenv(e); + + /* set the LANGUAGE env variable */ + strcpy(e, "LANGUAGE="); + strncat(e, language_codes[l - 1], 25 - 9); + putenv(e); } - setlocale(LC_ALL, ""); /* force to update getext */ + + /* Force to update gettext. */ + setlocale(LC_ALL, ""); } int language_count(void) @@ -51,26 +87,25 @@ int language_count(void) return LANG_NUMBER; } -int language_from_code(const char * code) +int language_from_code(const char *code) { int i; - for(i=0; i 0) - return language_codes[id-1]; - else - return ""; + return id > 0 ? language_codes[id - 1] : ""; }