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)
|
|
|
|
strcpy(buf, ((GString*)g_ptr_array_index(codes, index - 1))->str);
|
|
|
|
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-06-14 17:27:44 +02:00
|
|
|
free_g_string_array(&codes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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-09-29 15:41:16 +02:00
|
|
|
if(strcmp(local_code, ((GString*)g_ptr_array_index(codes, i))->str) == 0)
|
2005-06-14 17:27:44 +02:00
|
|
|
{
|
|
|
|
return_value = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_g_string_array(&codes);
|
|
|
|
|
|
|
|
return return_value;
|
|
|
|
}
|