LANGUAGE and env vars should work for stamps too, fallbacks should also work, also on Windows.

This commit is contained in:
Pere Pujal i Carabantes 2014-08-04 00:02:54 +00:00
parent 3d1f96f294
commit 85082b9092
3 changed files with 110 additions and 17 deletions

View file

@ -218,6 +218,9 @@ int need_right_to_left;
int need_right_to_left_word;
const char *lang_prefix, *short_lang_prefix;
int num_wished_langs = 0;
w_langs wished_langs[255];
static const language_to_locale_struct language_to_locale_array[] = {
{"english", "C"},
{"american-english", "C"},
@ -872,6 +875,27 @@ static int set_current_language(const char *restrict loc)
int i;
int y_nudge = 0;
char * oldloc;
char *env_language;
if (strlen(loc) > 0)
{
/* Got command line or config file language */
mysetenv("LANGUAGE", loc);
}
else
{
/* Find what language to use from env vars */
if (getenv("LANGUAGE") == NULL)
{
if (getenv("LC_ALL"))
mysetenv("LANGUAGE", getenv("LC_ALL"));
else if (getenv("LC_MESSAGES"))
mysetenv("LANGUAGE", getenv("LC_MESSAGES"));
else if (getenv("LANG"))
mysetenv("LANGUAGE", getenv("LANG"));
}
}
oldloc = strdup(loc);
@ -935,12 +959,50 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
set_langint_from_locale_string(oldloc);
} else {
#ifdef _WIN32
mysetenv("LANGUAGE", loc);
if (getenv("LANGUAGE") == NULL)
mysetenv("LANGUAGE", loc);
#endif
set_langint_from_locale_string(loc);
if (getenv("LANGUAGE") == NULL)
mysetenv("LANGUAGE", "C");
env_language = strdup(getenv("LANGUAGE"));
int j = 0;
char *env_language_lang;
if (*env_language)
{
env_language_lang = strtok(env_language, ":");
while (env_language_lang != NULL)
{
num_wished_langs++;
set_langint_from_locale_string(env_language_lang);
wished_langs[j].langint = langint;
wished_langs[j].lang_prefix = lang_prefixes[langint];
wished_langs[j].need_own_font = search_int_array(langint, lang_use_own_font);
wished_langs[j].need_right_to_left = search_int_array(langint, lang_use_right_to_left);
wished_langs[j].need_right_to_left_word = search_int_array(langint, lang_use_right_to_left_word);
for (i = 0; lang_y_nudge[i][0] != -1; i++)
{
// printf("lang_y_nudge[%d][0] = %d\n", i, lang_y_nudge[i][0]);
if (lang_y_nudge[i][0] == langint)
{
wished_langs[j].lang_y_nudge = lang_y_nudge[i][1];
//printf("y_nudge = %d\n", y_nudge);
break;
}
}
j++;
env_language_lang = strtok(NULL, ":");
}
if (*env_language)
free(env_language);
}
// set_langint_from_locale_string(loc);
}
#if 0
lang_prefix = lang_prefixes[langint];
short_lang_prefix = strdup(lang_prefix);
@ -962,7 +1024,7 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
break;
}
}
#endif
#ifdef DEBUG
fprintf(stderr, "DEBUG: Language is %s (%d) %s/%s\n",
lang_prefix, langint,
@ -977,7 +1039,7 @@ printf ("Locale AFTER is: %s\n", setlocale(LC_ALL,NULL));//EP
printf("lang_prefixes[%d] is \"%s\"\n", get_current_language(), lang_prefixes[get_current_language()]);
#endif
return y_nudge;
return wished_langs[0].lang_y_nudge;
}
int setup_i18n(const char *restrict lang, const char *restrict locale)

View file

@ -178,6 +178,20 @@ extern int need_own_font;
extern int need_right_to_left; // Right-justify
extern int need_right_to_left_word; // Words need to be reversed, too! (e.g., Hebrew, but not Arabic)
extern const char *lang_prefix, *short_lang_prefix;
extern int num_wished_langs;
typedef struct w_langs
{
int langint;
int need_own_font;
int need_right_to_left;
int need_right_to_left_word;
int lang_y_nudge;
const char *lang_prefix;
const char *short_lang_prefix;
} w_langs;
extern w_langs wished_langs[255];
/* Function prototypes: */

View file

@ -7031,6 +7031,14 @@ static void get_stamp_thumb(stamp_type * sd)
ratio = 1.0;
}
if (!sd->no_txt && !sd->stxt)
{
/* damn thing wants a .png extension; give it one */
memcpy(buf + len, ".png", 5);
sd->stxt = loaddesc(buf, &(sd->locale_text));
sd->no_txt = !sd->stxt;
}
#ifndef NOSOUND
/* good time to load the sound */
if (!sd->no_sound && !sd->ssnd && use_sound)
@ -7051,14 +7059,6 @@ static void get_stamp_thumb(stamp_type * sd)
}
#endif
if (!sd->no_txt && !sd->stxt)
{
/* damn thing wants a .png extension; give it one */
memcpy(buf + len, ".png", 5);
sd->stxt = loaddesc(buf, &(sd->locale_text));
sd->no_txt = !sd->stxt;
}
/* first see if we can re-use an existing thumbnail */
if (sd->thumbnail)
@ -10701,7 +10701,7 @@ static char *loaddesc(const char *const fname, Uint8 * locale_text)
char buf[512], def_buf[512]; /* doubled to 512 per TOYAMA Shin-Ichi's requested; -bjk 2007.05.10 */
int found, got_first;
FILE *fi;
int i;
txt_fname = strdup(fname);
*locale_text = 0;
@ -10749,21 +10749,38 @@ static char *loaddesc(const char *const fname, Uint8 * locale_text)
debug(buf);
/* Set the first available language */
for(i = 0; i < num_wished_langs; i++)
{
// lang_prefix = lang_prefixes[langint];
/* See if it's the one for this locale... */
if ((char *) strcasestr(buf, lang_prefix) == buf)
if ((char *) strcasestr(buf, wished_langs[i].lang_prefix) == buf)
{
debug(buf + strlen(lang_prefix));
if ((char *) strcasestr(buf + strlen(lang_prefix), ".utf8=") ==
buf + strlen(lang_prefix))
debug(buf + strlen(wished_langs[i].lang_prefix));
if ((char *) strcasestr(buf + strlen(wished_langs[i].lang_prefix), ".utf8=") ==
buf + strlen(wished_langs[i].lang_prefix))
{
lang_prefix = wished_langs[i].lang_prefix;
short_lang_prefix = strdup(lang_prefix);
/* When in doubt, cut off country code */
if (strchr(short_lang_prefix, '_'))
*strchr(short_lang_prefix, '_') = '\0';
need_own_font = wished_langs[i].need_own_font;
need_right_to_left = wished_langs[i].need_right_to_left;
need_right_to_left_word = wished_langs[i].need_right_to_left_word;
found = 1;
debug("...FOUND!");
}
}
}
}
}
while (!feof(fi) && !found);