bygfoot/src/language.c

115 lines
2.8 KiB
C
Raw Normal View History

2005-10-20 17:45:00 +02:00
/*
Bygfoot Football Manager -- a small and simple GTK2-based
football management game.
http://bygfoot.sourceforge.net
Copyright (C) 2005 Gyözö Both (gyboth@bygfoot.com)
This program 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
2005-06-14 17:27:44 +02:00
#include <locale.h>
2005-07-19 17:55:34 +02:00
2005-06-14 17:27:44 +02:00
#include "callbacks.h"
#include "free.h"
#include "language.h"
2005-06-26 13:42:01 +02:00
#include "lg_commentary.h"
2005-06-14 17:27:44 +02:00
#include "misc.h"
#include "option.h"
#include "variables.h"
#include "window.h"
2005-07-25 06:35:53 +02:00
#ifndef G_OS_UNIX
extern int _nl_msg_cat_cntr=0;
#endif
2005-06-14 17:27:44 +02:00
/** Set the game language to the specified one. */
void
language_set(gint index)
{
2005-07-19 17:55:34 +02:00
gchar buf[SMALL], buf2[SMALL];
gchar *pwd = g_get_current_dir();
2005-06-14 17:27:44 +02:00
GPtrArray *codes =
misc_separate_strings(const_str("string_language_codes"));
2005-07-17 13:55:33 +02:00
2005-06-14 17:27:44 +02:00
if(index > 0)
2005-10-05 21:59:37 +02:00
strcpy(buf, (gchar*)g_ptr_array_index(codes, index - 1));
2005-06-14 17:27:44 +02:00
else
strcpy(buf, "");
if(strcmp(buf, opt_str("string_opt_language_code")) != 0 ||
window.main == NULL)
{
2005-07-19 17:55:34 +02:00
#ifdef ENABLE_NLS
sprintf(buf2, "%s%slocale", pwd, G_DIR_SEPARATOR_S);
g_free(pwd);
if(g_file_test(buf2, G_FILE_TEST_EXISTS))
{
bindtextdomain (GETTEXT_PACKAGE, buf2);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
}
#endif
g_setenv ("LANGUAGE", buf, TRUE);
2005-06-14 17:27:44 +02:00
opt_set_str("string_opt_language_code", buf);
2005-07-19 17:55:34 +02:00
{
extern int _nl_msg_cat_cntr;
++_nl_msg_cat_cntr;
}
2005-06-14 17:27:44 +02:00
if(window.main != NULL)
{
window_destroy(&window.main, FALSE);
2005-06-26 13:42:01 +02:00
window_create(WINDOW_MAIN);
2005-06-14 17:27:44 +02:00
on_button_back_to_main_clicked(NULL, NULL);
}
}
2005-06-26 13:42:01 +02:00
lg_commentary_load_commentary_file_from_option();
2005-10-05 21:59:37 +02:00
free_gchar_array(&codes);
2005-06-14 17:27:44 +02:00
}
/** Get the index of the given code in the codes
array. */
gint
language_get_code_index(const gchar *code)
{
gint i, return_value = -1;
GPtrArray *codes =
misc_separate_strings(const_str("string_language_codes"));
2005-09-29 15:41:16 +02:00
gchar local_code[SMALL];
strcpy(local_code, code);
if(strcmp(code, "en") == 0)
strcpy(local_code, "C");
2005-06-14 17:27:44 +02:00
for(i=0;i<codes->len;i++)
2005-10-05 21:59:37 +02:00
if(strcmp(local_code, (gchar*)g_ptr_array_index(codes, i)) == 0)
2005-06-14 17:27:44 +02:00
{
return_value = i;
break;
}
2005-10-05 21:59:37 +02:00
free_gchar_array(&codes);
2005-06-14 17:27:44 +02:00
return return_value;
}