From 0045bbad985c769c0f3f0c42bcc301ae3d1c0d98 Mon Sep 17 00:00:00 2001 From: Albert Cahalan Date: Sat, 21 Nov 2009 10:14:56 +0000 Subject: [PATCH] i18n stuff belongs in i18n.c --- src/fonts.c | 28 +++++++++++----------------- src/i18n.c | 38 ++++++++++++++++++++++++++++++-------- src/i18n.h | 8 ++------ src/tuxpaint.c | 12 ++++++++++-- 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/src/fonts.c b/src/fonts.c index 96c25f386..dba66434b 100644 --- a/src/fonts.c +++ b/src/fonts.c @@ -249,23 +249,17 @@ TuxPaint_Font *load_locale_font(TuxPaint_Font * fallback, int size) ret = try_alternate_font(size); if (ret == NULL) { - 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(); + 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() + ); + smash_i18n(); } } diff --git a/src/i18n.c b/src/i18n.c index 9e09480c6..46ca4a23f 100644 --- a/src/i18n.c +++ b/src/i18n.c @@ -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(); +} diff --git a/src/i18n.h b/src/i18n.h index 1cfa8f80f..d45e6a669 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -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 diff --git a/src/tuxpaint.c b/src/tuxpaint.c index cdf7d5beb..ea8470f01 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -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