cleaned up some more
This commit is contained in:
parent
55c1588999
commit
c42798e061
1 changed files with 26 additions and 42 deletions
68
src/i18n.c
68
src/i18n.c
|
|
@ -314,8 +314,10 @@ static const language_to_locale_struct language_to_locale_array[] = {
|
||||||
|
|
||||||
/* FIXME: All this should REALLY be array-based!!! */
|
/* FIXME: All this should REALLY be array-based!!! */
|
||||||
/* Show available languages: */
|
/* Show available languages: */
|
||||||
static void show_lang_usage(FILE * f, const char *const prg)
|
static void show_lang_usage(int exitcode)
|
||||||
{
|
{
|
||||||
|
FILE * f = exitcode ? stderr : stdout;
|
||||||
|
const char *const prg = "tuxpaint"
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"\n"
|
"\n"
|
||||||
"Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
|
"Usage: %s [--lang LANGUAGE]\n" "\n" "LANGUAGE may be one of:\n"
|
||||||
|
|
@ -405,6 +407,7 @@ static void show_lang_usage(FILE * f, const char *const prg)
|
||||||
/* xh */ " xhosa\n"
|
/* xh */ " xhosa\n"
|
||||||
/* zam */" zapotec miahuatlan-zapotec\n"
|
/* zam */" zapotec miahuatlan-zapotec\n"
|
||||||
"\n", prg);
|
"\n", prg);
|
||||||
|
exit(exitcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -542,44 +545,18 @@ static void ctype_utf8(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void setup_language(const char *const prg, const char *langstr)
|
static const char *language_to_locale(const char *langstr)
|
||||||
{
|
{
|
||||||
if (!langstr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0];
|
int i = sizeof language_to_locale_array / sizeof language_to_locale_array[0];
|
||||||
const char *locale = NULL;
|
|
||||||
|
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
if (strcmp(langstr, language_to_locale_array[i].language))
|
if (!strcmp(langstr, language_to_locale_array[i].language))
|
||||||
continue;
|
return language_to_locale_array[i].locale;
|
||||||
locale = language_to_locale_array[i].locale;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
if (strcmp(langstr, "help") == 0 || strcmp(langstr, "list") == 0)
|
||||||
if (!locale)
|
show_lang_usage(0);
|
||||||
{
|
fprintf(stderr, "%s is an invalid language\n", langstr);
|
||||||
if (strcmp(langstr, "help") == 0 || strcmp(langstr, "list") == 0)
|
show_lang_usage(59);
|
||||||
{
|
|
||||||
show_lang_usage(stdout, prg);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "%s is an invalid language\n", langstr);
|
|
||||||
show_lang_usage(stderr, prg);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abuse_env("LANGUAGE",locale);
|
|
||||||
abuse_env("LC_ALL",locale);
|
|
||||||
|
|
||||||
// Specifies an implementation-dependent native environment.
|
|
||||||
// For XSI-conformant systems, this corresponds to the value
|
|
||||||
// of the associated environment variables, LC_* and LANG
|
|
||||||
setlocale(LC_ALL, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -611,8 +588,6 @@ static int set_current_language(void)
|
||||||
// internationalised environment and return the name of the locale().
|
// internationalised environment and return the name of the locale().
|
||||||
loc = setlocale(LC_MESSAGES, NULL);
|
loc = setlocale(LC_MESSAGES, NULL);
|
||||||
|
|
||||||
// FIXME: I'm getting back en_US.UTF-8 even after LC_ALL has been putenv()'d...?? -bjk 2008.02.19
|
|
||||||
|
|
||||||
if (loc && strstr(loc, "LC_MESSAGES"))
|
if (loc && strstr(loc, "LC_MESSAGES"))
|
||||||
loc = getenv("LANG");
|
loc = getenv("LANG");
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -622,9 +597,9 @@ static int set_current_language(void)
|
||||||
if (loc)
|
if (loc)
|
||||||
{
|
{
|
||||||
baseloc = strdup(loc);
|
baseloc = strdup(loc);
|
||||||
if (strchr(baseloc, '.'))
|
char *dot = strchr(baseloc, '.');
|
||||||
strcpy(strchr(baseloc, '.'), "\0");
|
if(dot)
|
||||||
|
*dot = '\0';
|
||||||
|
|
||||||
/* Which, if any, of the locales is it? */
|
/* Which, if any, of the locales is it? */
|
||||||
|
|
||||||
|
|
@ -652,8 +627,6 @@ static int set_current_language(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: These don't work because we have the wrong langint...!? -bjk 2008.02.19 */
|
|
||||||
|
|
||||||
lang_prefix = lang_prefixes[langint];
|
lang_prefix = lang_prefixes[langint];
|
||||||
|
|
||||||
short_lang_prefix = strdup(lang_prefix);
|
short_lang_prefix = strdup(lang_prefix);
|
||||||
|
|
@ -702,7 +675,18 @@ int setup_i18n(const char *restrict lang, const char *restrict locale)
|
||||||
abuse_env("LANG",locale);
|
abuse_env("LANG",locale);
|
||||||
setlocale(LC_ALL, ""); /* use arg ? */
|
setlocale(LC_ALL, ""); /* use arg ? */
|
||||||
}
|
}
|
||||||
setup_language("tuxpaint", lang);
|
if(lang)
|
||||||
|
{
|
||||||
|
const char *newlocale = language_to_locale(lang);
|
||||||
|
|
||||||
|
abuse_env("LANGUAGE",newlocale);
|
||||||
|
abuse_env("LC_ALL",newlocale);
|
||||||
|
|
||||||
|
// Specifies an implementation-dependent native environment.
|
||||||
|
// For XSI-conformant systems, this corresponds to the value
|
||||||
|
// of the associated environment variables, LC_* and LANG
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
}
|
||||||
ctype_utf8();
|
ctype_utf8();
|
||||||
int y_nudge = set_current_language();
|
int y_nudge = set_current_language();
|
||||||
printf("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]);
|
printf("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue