Language selection in-game is no more. It might return some day, but
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 17 Aug 2007 14:13:51 +0000 (14:13 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Fri, 17 Aug 2007 14:13:51 +0000 (14:13 +0000)
the implementation was really bothering me.  We were using putenv to
change the language (which didn't work on Windows anyway) and, more
importantly, we entirely broke the semantics of the LANGUAGE environment
variable.  You can find information on that in the ABOUT-NLS file
distributed with gettext.  (/usr/share/gettext/ABOUT-NLS on Debian.)

git-svn-id: https://s.snth.net/svn/neverball/trunk@1096 78b8d119-cf0a-0410-b17c-f493084dd1d7

Makefile
ball/main.c
ball/st_conf.c
putt/main.c
putt/st_conf.c
share/config.c
share/config.h
share/i18n.c
share/i18n.h
share/st_lang.c [deleted file]
share/st_lang.h [deleted file]

index 4116a09..b3347d0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -47,7 +47,6 @@ MAPC_OBJS= \
        share/mapc.o
 BALL_OBJS= \
        share/i18n.o    \
-       share/st_lang.o \
        share/st_resol.o \
        share/vec3.o    \
        share/base_image.o   \
@@ -88,7 +87,6 @@ BALL_OBJS= \
        ball/main.o
 PUTT_OBJS= \
        share/i18n.o    \
-       share/st_lang.o \
        share/st_resol.o \
        share/vec3.o   \
        share/base_image.o  \
index 1995ad2..0d55e0e 100644 (file)
@@ -323,10 +323,6 @@ int main(int argc, char *argv[])
     config_init();
     config_load();
 
-    /* Initialize the language */
-
-    language_set(language_from_code(config_simple_get_s(CONFIG_LANG)));
-
     /* Prepare run without GUI */
 
     if (replay_path)
index 0aa123e..0fac901 100644 (file)
@@ -24,7 +24,6 @@
 
 #include "st_conf.h"
 #include "st_title.h"
-#include "st_lang.h"
 #include "st_resol.h"
 #include "st_name.h"
 
@@ -45,9 +44,8 @@
 #define CONF_AUDHI  18
 #define CONF_AUDLO  19
 #define CONF_BACK   20
-#define CONF_LANG   21
-#define CONF_RES    22
-#define CONF_PLAYER 23
+#define CONF_RES    21
+#define CONF_PLAYER 22
 
 static int audlo_id;
 static int audhi_id;
@@ -160,10 +158,6 @@ static int conf_action(int i)
         goto_state(&st_title);
         break;
 
-    case CONF_LANG:
-        goto_state(&st_lang);
-        break;
-
     case CONF_RES:
         goto_state(&st_resol);
         break;
@@ -302,7 +296,6 @@ static int conf_enter(void)
                 music_id[ 1] = gui_state(kd, NULL, GUI_SML, 201, (m ==  1));
                 music_id[ 0] = gui_state(kd, NULL, GUI_SML, 200, (m ==  0));
             }
-            gui_state(jd, _(language_name(language_from_code(config_simple_get_s(CONFIG_LANG)))), GUI_SML, CONF_LANG, 0);
             gui_state(jd, config_simple_get_s(CONFIG_PLAYER), GUI_SML,
                       CONF_PLAYER, 0);
         }
@@ -328,7 +321,6 @@ static int conf_enter(void)
             gui_label(jd, _("Audio"),        GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Sound Volume"), GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Music Volume"), GUI_SML, GUI_ALL, 0, 0);
-            gui_label(jd, _("Language"),     GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Player Name"),  GUI_SML, GUI_ALL, 0, 0);
         }
         gui_layout(id, 0, 0);
index e84b87b..217fe7b 100644 (file)
@@ -157,10 +157,6 @@ int main(int argc, char *argv[])
                 config_init();
                 config_load();
 
-                /* Initialize the language. */
-
-                language_set(language_from_code(config_simple_get_s(CONFIG_LANG)));
-
                 /* Cache Neverball's camera setting. */
 
                 camera = config_get_d(CONFIG_CAMERA);
index f686de0..9602852 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "st_conf.h"
 #include "st_all.h"
-#include "st_lang.h"
 #include "st_resol.h"
 
 /*---------------------------------------------------------------------------*/
@@ -39,8 +38,7 @@
 #define CONF_AUDHI 18
 #define CONF_AUDLO 19
 #define CONF_BACK  20
-#define CONF_LANG  21
-#define CONF_RESOL 22
+#define CONF_RESOL 21
 
 static int audlo_id;
 static int audhi_id;
@@ -129,10 +127,6 @@ static int conf_action(int i)
         goto_state(&st_title);
         break;
 
-    case CONF_LANG:
-        goto_state(&st_lang);
-        break;
-
     case CONF_RESOL:
         goto_state(&st_resol);
         break;
@@ -261,7 +255,6 @@ static int conf_enter(void)
                 music_id[ 1] = gui_state(kd, NULL, GUI_SML, 201, (m ==  1));
                 music_id[ 0] = gui_state(kd, NULL, GUI_SML, 200, (m ==  0));
             }
-            gui_state(jd, _(language_name(language_from_code(config_simple_get_s(CONFIG_LANG)))), GUI_SML, CONF_LANG, 0);
         }
         if ((jd = gui_vstack(id)))
         {
@@ -280,7 +273,6 @@ static int conf_enter(void)
             gui_label(jd, _("Audio"),        GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Sound Volume"), GUI_SML, GUI_ALL, 0, 0);
             gui_label(jd, _("Music Volume"), GUI_SML, GUI_ALL, 0, 0);
-            gui_label(jd, _("Language"),     GUI_SML, GUI_ALL, 0, 0);
         }
         gui_layout(id, 0, 0);
     }
index cbfaf82..0b14e21 100644 (file)
@@ -111,7 +111,6 @@ void config_init(void)
     config_set_s(CONFIG_PLAYER,               DEFAULT_PLAYER);
     config_set_s(CONFIG_BALL,                 DEFAULT_BALL);
     config_set_s(CONFIG_BALL_BONUS,           DEFAULT_BALL_BONUS);
-    config_set_s(CONFIG_LANG,                 DEFAULT_LANG);
     config_set_d(CONFIG_KEY_FORWARD,          DEFAULT_KEY_FORWARD);
     config_set_d(CONFIG_KEY_BACKWARD,         DEFAULT_KEY_BACKWARD);
     config_set_d(CONFIG_KEY_LEFT,             DEFAULT_KEY_LEFT);
@@ -243,8 +242,6 @@ void config_load(void)
                     config_set_s(CONFIG_BALL,       val);
                 else if (strcmp(key, "ball_bonus") == 0)
                     config_set_s(CONFIG_BALL_BONUS, val);
-                else if (strcmp(key, "lang")       == 0)
-                    config_set_s(CONFIG_LANG,       val);
             }
 
         fclose(fp);
@@ -369,7 +366,6 @@ void config_save(void)
         fprintf(fp, "player               %s\n", option_s[CONFIG_PLAYER]);
         fprintf(fp, "ball                 %s\n", option_s[CONFIG_BALL]);
         fprintf(fp, "ball_bonus           %s\n", option_s[CONFIG_BALL_BONUS]);
-        fprintf(fp, "lang                 %s\n", option_s[CONFIG_LANG]);
 
         fclose(fp);
     }
index 1a3356a..e386af0 100644 (file)
@@ -87,7 +87,6 @@ enum {
     CONFIG_PLAYER,
     CONFIG_BALL,
     CONFIG_BALL_BONUS,
-    CONFIG_LANG,
 
     CONFIG_OPTION_S_COUNT
 };
@@ -141,7 +140,6 @@ enum {
 #define DEFAULT_PLAYER               ""
 #define DEFAULT_BALL                 "png/ball.png"
 #define DEFAULT_BALL_BONUS           "png/ball-bonus.png"
-#define DEFAULT_LANG                 ""
 #define DEFAULT_KEY_FORWARD          SDLK_UP
 #define DEFAULT_KEY_BACKWARD         SDLK_DOWN
 #define DEFAULT_KEY_LEFT             SDLK_LEFT
index 9478f1b..ee84143 100644 (file)
  */
 
 #include <string.h>
-#include <locale.h>
 #include <stdlib.h>
-#include <stdio.h>
-#include "i18n.h"
+#include <locale.h>
 
-static const char *languages[][2] = {
-    { "de", N_("German")  },
-    { "en", N_("English") },
-    { "es", N_("Spanish") },
-    { "fr", N_("French")  },
-    { "lv", N_("Latvian") },
-    { "nn", N_("Norwegian Nynorsk") },
-};
+#include "i18n.h"
 
 /*---------------------------------------------------------------------------*/
 
-void language_init(const char *domain, const char *locale_dir)
+void language_init(const char *domain, const char *default_dir)
 {
     char *dir = getenv("NEVERBALL_LOCALE");
 
     setlocale(LC_ALL, "");
-    bindtextdomain(domain, dir ? dir : locale_dir);
+
+    bindtextdomain(domain, dir ? dir : default_dir);
     bind_textdomain_codeset(domain, "UTF-8");
     textdomain(domain);
 }
 
-void language_set(int l)
-{
-    if (l == 0)
-        putenv("LANGUAGE");
-    else
-    {
-        static char e[25];
-
-        strcpy(e, "LANGUAGE=");
-        strncat(e, languages[l - 1][0], 25 - 9);
-
-        putenv(e);
-    }
-
-    /* Force to update gettext. */
-    setlocale(LC_ALL, "");
-}
-
-int language_count(void)
-{
-    return sizeof (languages) / sizeof (languages[0]);
-}
-
-int language_from_code(const char *code)
-{
-    int i;
-
-    for (i = 0; i < language_count(); i++)
-        if (strcmp(languages[i][0], code) == 0)
-            return i + 1;
-
-    return 0;
-}
-
-const char *language_name(int id)
-{
-    return id == 0 ? N_("System Default") : languages[id - 1][1];
-}
-
-
-const char *language_code(int id)
-{
-    return id > 0  ? languages[id - 1][0] : "";
-}
-
-/*---------------------------------------------------------------------------*/
-
 const char *sgettext(const char *msgid)
 {
     const char *msgval = gettext(msgid);
@@ -95,8 +40,7 @@ const char *sgettext(const char *msgid)
     {
         if ((msgval = strrchr(msgid, '^')))
             msgval++;
-        else
-            msgval = msgid;
+        else msgval = msgid;
     }
     return msgval;
 }
index 22a1945..a258fe2 100644 (file)
 /*---------------------------------------------------------------------------*/
 
 void language_init(const char *domain, const char *locale_dir);
-void language_set(int id);
-
-/*---------------------------------------------------------------------------*/
-
-int         language_count();
-int         language_from_code(const char *code);
-const char *language_name(int id);
-const char *language_code(int id);
-
-/*---------------------------------------------------------------------------*/
 
 const char *sgettext(const char *);
 
diff --git a/share/st_lang.c b/share/st_lang.c
deleted file mode 100644 (file)
index b50c7fa..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (C) 2003 Robert Kooima - 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.
- */
-
-#include <string.h>
-
-#include "gui.h"
-#include "back.h"
-#include "geom.h"
-#include "part.h"
-#include "audio.h"
-#include "config.h"
-
-#include "st_lang.h"
-#include "i18n.h"
-
-extern struct state st_conf;
-extern struct state st_null;
-
-static char **lang_names;
-
-/*---------------------------------------------------------------------------*/
-
-#define LANG_BACK 100
-
-static int lang_action(int i)
-{
-    int r = 1;
-
-    switch (i)
-    {
-    case LANG_BACK:
-        goto_state(&st_conf);
-        break;
-
-    default:
-        goto_state(&st_null);
-        language_set(i - 1);
-        config_set_s(CONFIG_LANG, language_code(i - 1));
-
-        goto_state(&st_conf);
-        break;
-    }
-
-    return r;
-}
-
-static int lang_enter(void)
-{
-    int id, jd, kd;
-    int i;
-    int l;
-    char *ln, *ln1, *ln2;
-
-    back_init("back/gui.png", config_get_d(CONFIG_GEOMETRY));
-
-    /* Initialize the language selection GUI. */
-    l = language_from_code(config_simple_get_s(CONFIG_LANG));
-
-    if ((id = gui_harray(0)))
-    {
-        if ((jd = gui_varray(id)))
-        {
-            if ((kd = gui_harray(jd)))
-            {
-                gui_label(kd, _("Language"), GUI_SML, GUI_ALL, 0, 0);
-                gui_filler(kd);
-                gui_start(kd, _("Back"), GUI_SML, LANG_BACK, 0);
-            }
-
-            lang_names = calloc(language_count(), sizeof(char *));
-
-            gui_state(jd, _(language_name(0)), GUI_SML, 1, (l == 0));
-            for (i = 1; i <= language_count(); i++)
-            {
-                language_set(i);
-                ln1 = _(language_name(i));
-                language_set(l);
-                ln2 = _(language_name(i));
-                if (strcmp(ln1, ln2) == 0)
-                    ln = ln1;
-                else
-                {
-                    ln = malloc(sizeof(char) * (strlen(ln1) + strlen(ln2) + 4));
-                    lang_names[i - 1] = ln;
-                    strcpy(ln, ln1);
-                    strcat(ln, " (");
-                    strcat(ln, ln2);
-                    strcat(ln, ")");
-                }
-
-                gui_state(jd, ln, GUI_SML, i + 1, (l == i));
-            }
-        }
-        gui_layout(id, 0, 0);
-    }
-
-    audio_music_fade_to(0.5f, "bgm/inter.ogg");
-
-    return id;
-}
-
-static void lang_leave(int id)
-{
-    int i;
-
-    for (i = 0; i < language_count(); i++)
-        if (lang_names[i] != NULL)
-            free(lang_names[i]);
-    free(lang_names);
-    back_free();
-    gui_delete(id);
-}
-
-static void lang_paint(int id, float st)
-{
-    config_push_persp((float) config_get_d(CONFIG_VIEW_FOV), 0.1f, FAR_DIST);
-    {
-        back_draw(0);
-    }
-    config_pop_matrix();
-    gui_paint(id);
-}
-
-static void lang_timer(int id, float dt)
-{
-    gui_timer(id, dt);
-    audio_timer(dt);
-}
-
-static void lang_point(int id, int x, int y, int dx, int dy)
-{
-    gui_pulse(gui_point(id, x, y), 1.2f);
-}
-
-static void lang_stick(int id, int a, int v)
-{
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_X, a))
-        gui_pulse(gui_stick(id, v, 0), 1.2f);
-    if (config_tst_d(CONFIG_JOYSTICK_AXIS_Y, a))
-        gui_pulse(gui_stick(id, 0, v), 1.2f);
-}
-
-static int lang_click(int b, int d)
-{
-    if (b < 0 && d == 1)
-        return lang_action(gui_token(gui_click()));
-    return 1;
-}
-
-static int lang_keybd(int c, int d)
-{
-    return (d && c == SDLK_ESCAPE) ? goto_state(&st_conf) : 1;
-}
-
-static int lang_buttn(int b, int d)
-{
-    if (d)
-    {
-        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_A, b))
-            return lang_action(gui_token(gui_click()));
-        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_B, b))
-            return goto_state(&st_conf);
-        if (config_tst_d(CONFIG_JOYSTICK_BUTTON_EXIT, b))
-            return goto_state(&st_conf);
-    }
-    return 1;
-}
-
-/*---------------------------------------------------------------------------*/
-
-
-struct state st_lang = {
-    lang_enter,
-    lang_leave,
-    lang_paint,
-    lang_timer,
-    lang_point,
-    lang_stick,
-    lang_click,
-    lang_keybd,
-    lang_buttn,
-    1, 0
-};
-
diff --git a/share/st_lang.h b/share/st_lang.h
deleted file mode 100644 (file)
index 5bc36c2..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef ST_LANG_H
-#define ST_LANG_H
-
-#include "state.h"
-
-extern struct state st_lang;
-
-#endif