bygfoot/src/language.c

70 lines
1.4 KiB
C
Raw Normal View History

2005-06-14 17:27:44 +02:00
#include <locale.h>
#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"
/** Set the game language to the specified one. */
void
language_set(gint index)
{
gchar buf[SMALL];
GPtrArray *codes =
misc_separate_strings(const_str("string_language_codes"));
2005-07-17 13:55:33 +02:00
gint lc = LC_ALL;
#ifdef G_OS_UNIX
lc = LC_MESSAGES;
#endif
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-17 13:55:33 +02:00
setlocale(lc, buf);
2005-06-14 17:27:44 +02:00
opt_set_str("string_opt_language_code", buf);
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"));
for(i=0;i<codes->len;i++)
if(strcmp(opt_str("string_opt_language_code"),
((GString*)g_ptr_array_index(codes, i))->str) == 0)
{
return_value = i;
break;
}
free_g_string_array(&codes);
return return_value;
}