Make game engine load the user's locale correctly (bug 688)
authorWuzzy <Wuzzy2@mail.ru>
Wed, 16 Jan 2019 00:37:26 +0100
changeset 14604 b86e6e4f3c58
parent 14603 62dea281e4d5
child 14605 13b22e2f2010
Make game engine load the user's locale correctly (bug #688)
ChangeLog.txt
QTfrontend/game.cpp
QTfrontend/net/hwmap.cpp
QTfrontend/net/hwmapoptimizer.cpp
QTfrontend/net/recorder.cpp
QTfrontend/net/tcpBase.cpp
QTfrontend/net/tcpBase.h
hedgewars/hwengine.pas
--- a/ChangeLog.txt	Wed Jan 16 00:01:29 2019 +0100
+++ b/ChangeLog.txt	Wed Jan 16 00:37:26 2019 +0100
@@ -58,6 +58,7 @@
  * Fix wind bar animation not looping properly
  * Fix airplane line being drawn above many HUD elements
  * Suppress “<team> is gone.” message at end of game
+ * Fix game engine ignoring appropriate number formatting of user language
 
 Frontend:
  + Restructure credits
--- a/QTfrontend/game.cpp	Wed Jan 16 00:01:29 2019 +0100
+++ b/QTfrontend/game.cpp	Wed Jan 16 00:37:26 2019 +0100
@@ -53,7 +53,7 @@
 QString trainingName, trainingScript, trainingTeam, campaign, campaignScript, campaignTeam; // TODO: Cleaner solution?
 
 HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, QString ammo, TeamSelWidget* pTeamSelWidget) :
-    TCPBase(true, 0),
+    TCPBase(true, !config->language().isEmpty(), 0),
     ammostr(ammo),
     m_pTeamSelWidget(pTeamSelWidget)
 {
--- a/QTfrontend/net/hwmap.cpp	Wed Jan 16 00:01:29 2019 +0100
+++ b/QTfrontend/net/hwmap.cpp	Wed Jan 16 00:37:26 2019 +0100
@@ -25,7 +25,7 @@
 #include "hwmap.h"
 
 HWMap::HWMap(QObject * parent) :
-    TCPBase(false, parent)
+    TCPBase(false, false, parent)
 {
     templateFilter = 0;
     m_mapgen = MAPGEN_REGULAR;
--- a/QTfrontend/net/hwmapoptimizer.cpp	Wed Jan 16 00:01:29 2019 +0100
+++ b/QTfrontend/net/hwmapoptimizer.cpp	Wed Jan 16 00:37:26 2019 +0100
@@ -2,7 +2,7 @@
 #include "hwconsts.h"
 
 HWMapOptimizer::HWMapOptimizer(QObject *parent) :
-    TCPBase(parent)
+    TCPBase(false, false, parent)
 {
 }
 
--- a/QTfrontend/net/recorder.cpp	Wed Jan 16 00:01:29 2019 +0100
+++ b/QTfrontend/net/recorder.cpp	Wed Jan 16 00:37:26 2019 +0100
@@ -33,7 +33,7 @@
 static QList<HWRecorder*> queue;
 
 HWRecorder::HWRecorder(GameUIConfig * config, const QString &prefix) :
-    TCPBase(false)
+    TCPBase(false, !config->language().isEmpty())
 {
     this->config = config;
     this->prefix = prefix;
--- a/QTfrontend/net/tcpBase.cpp	Wed Jan 16 00:01:29 2019 +0100
+++ b/QTfrontend/net/tcpBase.cpp	Wed Jan 16 00:37:26 2019 +0100
@@ -21,10 +21,12 @@
 #include <QImage>
 #include <QThread>
 #include <QApplication>
+#include <QProcessEnvironment>
 
 #include "tcpBase.h"
 #include "hwconsts.h"
 #include "MessageDialog.h"
+#include "gameuiconfig.h"
 
 #ifdef HWLIBRARY
 extern "C" {
@@ -104,11 +106,12 @@
 
 }
 
-TCPBase::TCPBase(bool demoMode, QObject *parent) :
+TCPBase::TCPBase(bool demoMode, bool usesCustomLanguage, QObject *parent) :
     QObject(parent),
     m_hasStarted(false),
     m_isDemoMode(demoMode),
     m_connected(false),
+    m_usesCustomLanguage(usesCustomLanguage),
     IPCSocket(0)
 {
     process = 0;
@@ -183,6 +186,18 @@
     process->setProcessChannelMode(QProcess::ForwardedChannels);
 #endif
 
+    // If game config uses non-system locale, we set the environment
+    // of the engine first
+    if(m_usesCustomLanguage)
+    {
+        QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
+        QString hwengineLang = QLocale().name() + ".UTF8";
+        qDebug("Setting hwengine environment: LANG=%s", qPrintable(hwengineLang));
+        // TODO: Check if this is correct and works on all systems
+        env.insert("LANG", QLocale().name() + ".UTF8");
+        process->setProcessEnvironment(env);
+    }
+    qDebug("Starting hwengine ...");
     process->start(bindir->absolutePath() + "/hwengine", arguments);
 #endif
     m_hasStarted = true;
--- a/QTfrontend/net/tcpBase.h	Wed Jan 16 00:01:29 2019 +0100
+++ b/QTfrontend/net/tcpBase.h	Wed Jan 16 00:37:26 2019 +0100
@@ -41,7 +41,7 @@
         Q_OBJECT
 
     public:
-        TCPBase(bool demoMode, QObject * parent = 0);
+        TCPBase(bool demoMode, bool usesCustomLanguage, QObject * parent = 0);
         virtual ~TCPBase();
 
         virtual bool couldBeRemoved();
@@ -80,6 +80,7 @@
 #endif
         bool m_isDemoMode;
         bool m_connected;
+        bool m_usesCustomLanguage;
         void RealStart();
         QPointer<QTcpSocket> IPCSocket;
 
--- a/hedgewars/hwengine.pas	Wed Jan 16 00:01:29 2019 +0100
+++ b/hedgewars/hwengine.pas	Wed Jan 16 00:37:26 2019 +0100
@@ -36,6 +36,7 @@
      {$IFDEF USE_VIDEO_RECORDING}, uVideoRec {$ENDIF}
      {$IFDEF USE_TOUCH_INTERFACE}, uTouch {$ENDIF}
      {$IFDEF ANDROID}, GLUnit{$ENDIF}
+     {$IFDEF UNIX}, clocale{$ENDIF}
      {$IFDEF WINDOWS}, dynlibs{$ENDIF}
      ;