diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-02-16 12:27:28 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-02-16 12:56:49 +0100 |
commit | c011007165a6dee12f0b856411a8c8deaeb2d289 (patch) | |
tree | e9c73af454b4ff08f7d836ac5de98500f87b994a /gui | |
parent | 7ea413f202d5716de7155df46e708ce5825771d1 (diff) |
gui/init: allow forcing locale via env
Issue: #748
Diffstat (limited to 'gui')
-rw-r--r-- | gui/init.cpp | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/gui/init.cpp b/gui/init.cpp index 5879c6c0..cf0b53c8 100644 --- a/gui/init.cpp +++ b/gui/init.cpp @@ -157,10 +157,13 @@ void attach_parent_console() _wfreopen(L"CON", L"w", stdout); _wfreopen(L"CON", L"w", stderr); _wfreopen(L"CON", L"r", stdin); - freopen("CON", "w", stdout); freopen("CON", "w", stderr); freopen("CON", "w", stderr); + + // skip prompt in cmd.exe window + fprintf(stderr, "\n"); + fflush(stderr); } } @@ -182,10 +185,6 @@ int run_window(QApplication& app, std::unique_ptr<QWidget> main_window) int otr_main(int argc, char** argv, std::function<QWidget*()> make_main_window) { -#ifdef _WIN32 - attach_parent_console(); -#endif - #if defined OTR_HAS_DENORM_CONTROL set_fp_mask(); #endif @@ -197,38 +196,43 @@ int otr_main(int argc, char** argv, std::function<QWidget*()> make_main_window) #ifdef _WIN32 add_win32_path(); + attach_parent_console(); #endif QDir::setCurrent(OPENTRACK_BASE_PATH); -#if 0 -#if !defined(__linux) && !defined _WIN32 - // workaround QTBUG-38598 - QCoreApplication::addLibraryPath("."); -#endif -#endif - set_qt_style(); QTranslator t; - // QLocale::setDefault(QLocale("ru_RU")); // force i18n for testing - - if (group::with_global_settings_object([&](QSettings& s) { - return !s.value("disable-translation", false).toBool(); - })) { - (void) t.load(QLocale(), "", "", OPENTRACK_BASE_PATH + "/" OPENTRACK_I18N_PATH, ".qm"); - (void) QCoreApplication::installTranslator(&t); + const char* forced_locale = getenv("OTR_FORCE_LOCALE"); + + if (forced_locale) + { + QLocale::setDefault(QLocale(forced_locale)); // force i18n for testing + qDebug() << "locale:" << forced_locale; + } + + const bool no_i18n = group::with_global_settings_object([](QSettings& s) { + return !s.value("disable-translation", false).toBool(); + }); + + if (forced_locale || !no_i18n) + { + (void) t.load(QLocale(), "", "", OPENTRACK_BASE_PATH + "/" OPENTRACK_I18N_PATH, ".qm"); + (void) QCoreApplication::installTranslator(&t); + } } int ret = run_window(app, std::unique_ptr<QWidget>(make_main_window())); +#if 0 // msvc crashes in Qt plugin system's dtor // Note: QLibrary::PreventUnloadHint seems to workaround it -#if defined(_MSC_VER) && 0 - qDebug() << "exit: terminating"; +#if defined _MSC_VER TerminateProcess(GetCurrentProcess(), 0); #endif +#endif return ret; } |