From 7707893f6f6ca1584711a77586b58bbea1553bf1 Mon Sep 17 00:00:00 2001 From: "J.B. Langston" Date: Mon, 6 May 2019 22:06:37 -0500 Subject: [PATCH] Automatically set tutorial language from qt locale --- src/include/i18n.h | 1 + src/ui/ui-drv/qt/main.cpp | 6 ++++++ src/ui/ui.c | 31 +++++++++++-------------------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/include/i18n.h b/src/include/i18n.h index 09ef6d30..e040c479 100644 --- a/src/include/i18n.h +++ b/src/include/i18n.h @@ -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 diff --git a/src/ui/ui-drv/qt/main.cpp b/src/ui/ui-drv/qt/main.cpp index 20a78303..04c875e3 100644 --- a/src/ui/ui-drv/qt/main.cpp +++ b/src/ui/ui-drv/qt/main.cpp @@ -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) { diff --git a/src/ui/ui.c b/src/ui/ui.c index bf24811e..6cafc51a 100644 --- a/src/ui/ui.c +++ b/src/ui/ui.c @@ -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 (); @@ -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, ""); @@ -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"); @@ -1061,9 +1058,17 @@ 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"); } @@ -1071,17 +1076,7 @@ ui_init (int argc, char **argv) #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", @@ -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);