i18n stuff belongs in i18n.c

This commit is contained in:
Albert Cahalan 2009-11-21 10:14:56 +00:00
parent dd90d90624
commit 0045bbad98
4 changed files with 53 additions and 33 deletions

View file

@ -249,23 +249,17 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size)
ret = try_alternate_font(size);
if (ret == NULL)
{
fprintf(stderr,
fprintf(
stderr,
"\nWarning: Can't load font for this locale:\n"
"%s\n"
"The Simple DirectMedia Layer error that occurred was:\n"
"%s\n\n"
"Will use default (American English) instead.\n\n",
str, SDL_GetError());
/* Revert to default: */
putenv((char *) "LANG=C");
putenv((char *) "OUTPUT_CHARSET=C");
setlocale(LC_ALL, "C");
ctype_utf8();
set_current_language();
str,
SDL_GetError()
);
smash_i18n();
}
}

View file

@ -182,7 +182,7 @@ int need_right_to_left;
int need_right_to_left_word;
const char *lang_prefix, *short_lang_prefix;
const language_to_locale_struct language_to_locale_array[] = {
static const language_to_locale_struct language_to_locale_array[] = {
{"english", "C"},
{"american-english", "C"},
{"arabic", "ar_SA.UTF-8"},
@ -327,7 +327,7 @@ static int search_int_array(int l, int *array)
return 0;
}
void set_langstr(const char *s)
static void set_langstr(const char *s)
{
if (langstr)
free(langstr);
@ -336,7 +336,7 @@ void set_langstr(const char *s)
// This is to ensure that iswprint() works beyond ASCII,
// even if the locale wouldn't normally support that.
void ctype_utf8(void)
static void ctype_utf8(void)
{
#ifndef _WIN32
const char *names[] = {"en_US.UTF8","en_US.UTF-8","UTF8","UTF-8",};
@ -348,7 +348,7 @@ void ctype_utf8(void)
/* Determine the current language/locale, and set the language string: */
int set_current_language(void)
static int set_current_language(void)
{
char *loc, *baseloc;
int i, found;
@ -476,7 +476,7 @@ int get_current_language(void)
/* FIXME: All this should REALLY be array-based!!! */
/* Show available languages: */
void show_lang_usage(FILE * f, const char *const prg)
static void show_lang_usage(FILE * f, const char *const prg)
{
fprintf(f,
"\n"
@ -572,7 +572,7 @@ void show_lang_usage(FILE * f, const char *const prg)
/* FIXME: Add accented characters to the descriptions */
/* Show available locales: */
void show_locale_usage(FILE * f, const char *const prg)
static void show_locale_usage(FILE * f, const char *const prg)
{
fprintf(f,
"\n"
@ -665,7 +665,7 @@ void show_locale_usage(FILE * f, const char *const prg)
"\n", prg);
}
void setup_language(const char *const prg, int * y_nudge)
static void setup_language(const char *const prg, int * y_nudge)
{
if (langstr != NULL)
{
@ -725,7 +725,7 @@ void setup_language(const char *const prg, int * y_nudge)
// handle --locale arg
void do_locale_option(const char *const arg)
static void do_locale_option(const char *const arg)
{
int len = strlen(arg) + 6;
char *str = malloc(len);
@ -737,3 +737,25 @@ void do_locale_option(const char *const arg)
setlocale(LC_ALL, ""); /* use arg ? */
ctype_utf8();
}
void setup_i18n(const char *restrict lang, const char *restrict locale, int *button_label_y_nudge)
{
if(lang)
set_langstr(lang);
if(locale)
do_locale_option(locale);
setup_language("tuxpaint", button_label_y_nudge);
printf("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]);
// ctype_utf8 set_current_language
}
void smash_i18n(void)
{
putenv((char *) "LANG=C");
putenv((char *) "OUTPUT_CHARSET=C");
setlocale(LC_ALL, "C");
ctype_utf8();
set_current_language();
}

View file

@ -152,14 +152,10 @@ extern const language_to_locale_struct language_to_locale_array[];
/* Function prototypes: */
void set_langstr(const char *s);
int set_current_language(void);
int get_current_language(void);
void show_lang_usage(FILE * f, const char *const prg);
void show_locale_usage(FILE * f, const char *const prg);
void setup_language(const char *const prg, int * y_nudge);
void do_locale_option(const char *const arg);
void ctype_utf8(void);
void setup_i18n(const char *restrict lang, const char *restrict locale, int *button_label_y_nudge);
void smash_i18n(void);
#endif

View file

@ -19077,12 +19077,22 @@ static void setup_config(char *argv[])
datadir = tmpcfg.datadir ? tmpcfg.datadir : savedir;
setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale, &button_label_y_nudge);
#if 0
if(tmpcfg.parsertmp_lang)
set_langstr(tmpcfg.parsertmp_lang);
if(tmpcfg.parsertmp_locale)
do_locale_option(tmpcfg.parsertmp_locale);
setup_language(getfilename(argv[0]), &button_label_y_nudge);
/* printf("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]); */
ctype_utf8 set_current_language
#endif
#if 0
all_locale_fonts
no_system_fonts
@ -20382,8 +20392,6 @@ int main(int argc, char *argv[])
progname = argv[0];
chdir_to_binary(argv[0]);
setup_config(argv);
setup_language(getfilename(argv[0]), &button_label_y_nudge);
/* printf("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]); */
CLOCK_ASM(time2);
#ifdef FORKED_FONTS