lang/locale work much better now
This commit is contained in:
parent
778f51cc58
commit
db4ad99ad8
4 changed files with 86 additions and 18 deletions
68
src/i18n.c
68
src/i18n.c
|
|
@ -517,12 +517,14 @@ int get_current_language(void)
|
||||||
return langint;
|
return langint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ABUSE_ENV
|
||||||
static void abuse_env(const char *restrict name, const char *restrict value)
|
static void abuse_env(const char *restrict name, const char *restrict value)
|
||||||
{
|
{
|
||||||
char s[40];
|
char s[40];
|
||||||
snprintf(s, sizeof s, "%s=%s", name, value);
|
snprintf(s, sizeof s, "%s=%s", name, value);
|
||||||
putenv(strdup(s));
|
putenv(strdup(s));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int search_int_array(int l, int *array)
|
static int search_int_array(int l, int *array)
|
||||||
{
|
{
|
||||||
|
|
@ -564,7 +566,7 @@ static const char *language_to_locale(const char *langstr)
|
||||||
show_lang_usage(59);
|
show_lang_usage(59);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_langint_from_locale_string(const char *restrict loc)
|
static void set_langint_from_locale_string(const char *restrict loc)
|
||||||
{
|
{
|
||||||
if (!loc)
|
if (!loc)
|
||||||
return;
|
return;
|
||||||
|
|
@ -604,13 +606,15 @@ void set_langint_from_locale_string(const char *restrict loc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_current_language(void) MUST_CHECK;
|
static int set_current_language(const char *restrict locale_choice) MUST_CHECK;
|
||||||
static int set_current_language(void)
|
static int set_current_language(const char *restrict loc)
|
||||||
{
|
{
|
||||||
char *loc;
|
|
||||||
int i;
|
int i;
|
||||||
int y_nudge = 0;
|
int y_nudge = 0;
|
||||||
|
|
||||||
|
setlocale(LC_ALL, loc);
|
||||||
|
ctype_utf8();
|
||||||
|
|
||||||
bindtextdomain("tuxpaint", LOCALEDIR);
|
bindtextdomain("tuxpaint", LOCALEDIR);
|
||||||
/* Old version of glibc does not have bind_textdomain_codeset() */
|
/* Old version of glibc does not have bind_textdomain_codeset() */
|
||||||
#if defined __GLIBC__ && __GLIBC__ == 2 && __GLIBC_MINOR__ >=2 || __GLIBC__ > 2 || __APPLE__
|
#if defined __GLIBC__ && __GLIBC__ == 2 && __GLIBC_MINOR__ >=2 || __GLIBC__ > 2 || __APPLE__
|
||||||
|
|
@ -620,20 +624,28 @@ static int set_current_language(void)
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
bind_textdomain_codeset("tuxpaint", "UTF-8");
|
bind_textdomain_codeset("tuxpaint", "UTF-8");
|
||||||
|
#ifdef ABUSE_ENV
|
||||||
loc = getenv("LANGUAGE");
|
loc = getenv("LANGUAGE");
|
||||||
if (!loc)
|
if (!loc)
|
||||||
|
#else
|
||||||
|
if (!*loc)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
loc = _nl_locale_name(LC_MESSAGES, "");
|
loc = _nl_locale_name(LC_MESSAGES, "");
|
||||||
|
#ifdef ABUSE_ENV
|
||||||
if (loc)
|
if (loc)
|
||||||
abuse_env("LANGUAGE",loc);
|
abuse_env("LANGUAGE",loc);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// NULL: Used to direct setlocale() to query the current
|
// NULL: Used to direct setlocale() to query the current
|
||||||
// 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);
|
||||||
|
|
||||||
|
#ifdef ABUSE_ENV
|
||||||
if (loc && strstr(loc, "LC_MESSAGES"))
|
if (loc && strstr(loc, "LC_MESSAGES"))
|
||||||
loc = getenv("LANG");
|
loc = getenv("LANG");
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
set_langint_from_locale_string(loc);
|
set_langint_from_locale_string(loc);
|
||||||
|
|
@ -642,8 +654,8 @@ static int set_current_language(void)
|
||||||
|
|
||||||
short_lang_prefix = strdup(lang_prefix);
|
short_lang_prefix = strdup(lang_prefix);
|
||||||
/* When in doubt, cut off country code */
|
/* When in doubt, cut off country code */
|
||||||
if (strchr(short_lang_prefix, '_') != NULL)
|
if (strchr(short_lang_prefix, '_'))
|
||||||
strcpy(strchr(short_lang_prefix, '_'), "\0");
|
*strchr(short_lang_prefix, '_') = '\0';
|
||||||
|
|
||||||
need_own_font = search_int_array(langint, lang_use_own_font);
|
need_own_font = search_int_array(langint, lang_use_own_font);
|
||||||
need_right_to_left = search_int_array(langint, lang_use_right_to_left);
|
need_right_to_left = search_int_array(langint, lang_use_right_to_left);
|
||||||
|
|
@ -672,7 +684,7 @@ static int set_current_language(void)
|
||||||
return y_nudge;
|
return y_nudge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ABUSE_ENV
|
||||||
int setup_i18n(const char *restrict lang, const char *restrict locale)
|
int setup_i18n(const char *restrict lang, const char *restrict locale)
|
||||||
{
|
{
|
||||||
printf("lang %p, locale %p\n", lang, locale);
|
printf("lang %p, locale %p\n", lang, locale);
|
||||||
|
|
@ -685,7 +697,6 @@ int setup_i18n(const char *restrict lang, const char *restrict locale)
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
abuse_env("LANG",locale);
|
abuse_env("LANG",locale);
|
||||||
setlocale(LC_ALL, ""); /* use arg ? */
|
|
||||||
}
|
}
|
||||||
if(lang)
|
if(lang)
|
||||||
{
|
{
|
||||||
|
|
@ -693,21 +704,42 @@ int setup_i18n(const char *restrict lang, const char *restrict locale)
|
||||||
|
|
||||||
abuse_env("LANGUAGE",newlocale);
|
abuse_env("LANGUAGE",newlocale);
|
||||||
abuse_env("LC_ALL",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();
|
// The "" is being passed to setlocale.
|
||||||
return set_current_language();
|
// It specifies an implementation-dependent native environment.
|
||||||
|
// For XSI-conformant systems, this corresponds to the value
|
||||||
|
// of the associated environment variables, LC_* and LANG
|
||||||
|
return set_current_language("");
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
int setup_i18n(const char *restrict lang, const char *restrict locale)
|
||||||
|
{
|
||||||
|
printf("lang %p, locale %p\n", lang, locale);
|
||||||
|
printf("lang \"%s\", locale \"%s\"\n", lang, locale);
|
||||||
|
|
||||||
|
if(locale)
|
||||||
|
{
|
||||||
|
if(!strcmp(locale,"help"))
|
||||||
|
{
|
||||||
|
show_locale_usage(stdout,"tuxpaint");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
locale = "";
|
||||||
|
|
||||||
|
if(lang)
|
||||||
|
locale = language_to_locale(lang);
|
||||||
|
|
||||||
|
return set_current_language(locale);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int smash_i18n(void)
|
int smash_i18n(void)
|
||||||
{
|
{
|
||||||
|
#ifdef ABUSE_ENV
|
||||||
putenv((char *) "LANG=C");
|
putenv((char *) "LANG=C");
|
||||||
putenv((char *) "OUTPUT_CHARSET=C");
|
putenv((char *) "OUTPUT_CHARSET=C");
|
||||||
setlocale(LC_ALL, "C");
|
#endif
|
||||||
ctype_utf8();
|
return set_current_language("C");
|
||||||
return set_current_language();
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
const char PARSE_YES[] = "yes";
|
const char PARSE_YES[] = "yes";
|
||||||
const char PARSE_NO[] = "no";
|
const char PARSE_NO[] = "no";
|
||||||
|
const char PARSE_CLOBBER[] = ":-("; // for painful lang/locale priority situation
|
||||||
|
|
||||||
struct cfg
|
struct cfg
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
extern const char PARSE_YES[];
|
extern const char PARSE_YES[];
|
||||||
extern const char PARSE_NO[];
|
extern const char PARSE_NO[];
|
||||||
|
extern const char PARSE_CLOBBER[];
|
||||||
|
|
||||||
struct cfginfo
|
struct cfginfo
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18945,6 +18945,20 @@ static void parse_file_options(struct cfginfo *restrict tmpcfg, const char *file
|
||||||
parse_one_option(tmpcfg,str,strdup(arg),filename);
|
parse_one_option(tmpcfg,str,strdup(arg),filename);
|
||||||
}
|
}
|
||||||
fclose(fi);
|
fclose(fi);
|
||||||
|
|
||||||
|
// These interact in horrid ways.
|
||||||
|
if(tmpcfg->parsertmp_lang && tmpcfg->parsertmp_locale)
|
||||||
|
fprintf(
|
||||||
|
stderr,
|
||||||
|
"Warning: option 'lang=%s' overrides option 'locale=%s' in '%s'\n",
|
||||||
|
tmpcfg->parsertmp_lang,
|
||||||
|
tmpcfg->parsertmp_locale,
|
||||||
|
filename
|
||||||
|
);
|
||||||
|
if(tmpcfg->parsertmp_lang)
|
||||||
|
tmpcfg->parsertmp_locale = PARSE_CLOBBER;
|
||||||
|
else if(tmpcfg->parsertmp_locale)
|
||||||
|
tmpcfg->parsertmp_lang = PARSE_CLOBBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parse_argv_options(struct cfginfo *restrict tmpcfg, char *argv[])
|
static void parse_argv_options(struct cfginfo *restrict tmpcfg, char *argv[])
|
||||||
|
|
@ -18989,6 +19003,22 @@ static void parse_argv_options(struct cfginfo *restrict tmpcfg, char *argv[])
|
||||||
fprintf(stderr, "%s is not understood\n", *argv);
|
fprintf(stderr, "%s is not understood\n", *argv);
|
||||||
show_usage(63);
|
show_usage(63);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These interact in horrid ways.
|
||||||
|
if(tmpcfg->parsertmp_lang && tmpcfg->parsertmp_locale)
|
||||||
|
{
|
||||||
|
fprintf(
|
||||||
|
stderr,
|
||||||
|
"Error: command line option '--lang=%s' overrides option '--locale=%s'\n",
|
||||||
|
tmpcfg->parsertmp_lang,
|
||||||
|
tmpcfg->parsertmp_locale
|
||||||
|
);
|
||||||
|
exit(92);
|
||||||
|
}
|
||||||
|
if(tmpcfg->parsertmp_lang)
|
||||||
|
tmpcfg->parsertmp_locale = PARSE_CLOBBER;
|
||||||
|
else if(tmpcfg->parsertmp_locale)
|
||||||
|
tmpcfg->parsertmp_lang = PARSE_CLOBBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
// merge two configs, with the winner taking priority
|
// merge two configs, with the winner taking priority
|
||||||
|
|
@ -19091,6 +19121,10 @@ static void setup_config(char *argv[])
|
||||||
|
|
||||||
datadir = tmpcfg.datadir ? tmpcfg.datadir : savedir;
|
datadir = tmpcfg.datadir ? tmpcfg.datadir : savedir;
|
||||||
|
|
||||||
|
if(tmpcfg.parsertmp_lang == PARSE_CLOBBER)
|
||||||
|
tmpcfg.parsertmp_lang = NULL;
|
||||||
|
if(tmpcfg.parsertmp_locale == PARSE_CLOBBER)
|
||||||
|
tmpcfg.parsertmp_locale = NULL;
|
||||||
button_label_y_nudge = setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale);
|
button_label_y_nudge = setup_i18n(tmpcfg.parsertmp_lang, tmpcfg.parsertmp_locale);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue