Skip to content

Commit

Permalink
Automatically set tutorial language from qt locale
Browse files Browse the repository at this point in the history
  • Loading branch information
jblang committed May 7, 2019
1 parent f746cb0 commit 7707893
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/include/i18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#define bindtextdomain(x, y) (y)
#define textdomain(x)
const char *qt_gettext(const char *text);
const char *qt_locale();
#define gettext(STRING) qt_gettext(STRING)

#else
Expand Down
6 changes: 6 additions & 0 deletions src/ui/ui-drv/qt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ static struct params params[] = {

extern "C" {

const char
*qt_locale()
{
return QLocale::system().name().toStdString().c_str();
}

const char
*qt_gettext(char *text)
{
Expand Down
31 changes: 11 additions & 20 deletions src/ui/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -1018,9 +1018,7 @@ ui_init (int argc, char **argv)
int i;
int width, height;
char welcome[MAX_WELCOME], language[20];
#ifdef HAVE_GETTEXT
char *locale;
#endif
char *locale = NULL;
#ifdef DESTICKY
euid = geteuid ();
egid = getegid ();
Expand All @@ -1030,7 +1028,6 @@ ui_init (int argc, char **argv)
setegid (getgid ());
#endif

strcpy (language, "en");
#ifdef HAVE_GETTEXT
/* Setting all locales for XaoS: */
locale = setlocale (LC_MESSAGES, "");
Expand All @@ -1039,7 +1036,7 @@ ui_init (int argc, char **argv)
printf ("I18n menus will not be available.\n");
}
#ifdef _WIN32
// x_message("%s",locale);
/* Convert from windows language name to ISO 639-1 language code */
if (locale != NULL) {
if (strncmp (locale, "Hungarian", 9) == 0)
strcpy (language, "hu");
Expand All @@ -1061,27 +1058,25 @@ ui_init (int argc, char **argv)
strcpy (language, "pt");
}
#else
bind_textdomain_codeset ("xaos", "UTF-8");
#endif
#endif
#ifdef QT_GETTEXT
locale = qt_locale();
#endif
if (locale != NULL && strcmp (locale, "C") != 0) {
strcpy(language, locale);
language[2] = '\0';
language[2] = '\0';
} else {
strcpy (language, "en");
}




#ifdef DEBUG
printf ("Trying to use locale settings for %s.\n", locale);
#endif

#endif
#ifdef DEBUG
printf ("Using catalog file for %s language.\n", language);
#endif
/* Without this some locales (e.g. the Hungarian) replaces "." to ","
in numerical format and this will cause an automatic truncation
at each parameter at certain places, e.g. drawing a new fractal. */
setlocale (LC_NUMERIC, "C");
#ifdef DEBUG
printf ("Text domain will be bound to directory %s.\n",
#endif
bindtextdomain ("xaos",
Expand All @@ -1108,12 +1103,8 @@ ui_init (int argc, char **argv)
#endif
#endif
;
#ifndef _WIN32
bind_textdomain_codeset ("xaos", "UTF-8");
#endif
textdomain ("xaos");
/* Done setting locales. */
#endif
xio_init (argv[0]);
params_register (global_params);
params_register (ui_fractal_params);
Expand Down

0 comments on commit 7707893

Please sign in to comment.