Skip to content

Commit 5b6b60c

Browse files
committed
Auto choose language depending on system
Fix translation some fixes
1 parent 6b7c74b commit 5b6b60c

File tree

7 files changed

+68
-17
lines changed

7 files changed

+68
-17
lines changed

Libs/GamePath.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import os.path
22
import winreg
33
from vdf import loads
4-
from subprocess import check_output
4+
import subprocess
55

66

77
def get_user_logon_name():
8+
startupinfo = subprocess.STARTUPINFO()
9+
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
10+
startupinfo.wShowWindow = subprocess.SW_HIDE
11+
812
ps = "(Get-CimInstance -ClassName Win32_ComputerSystem).Username;"
9-
res = check_output(
13+
14+
res = subprocess.check_output(
1015
["powershell", "-NoProfile", "-Command", ps],
11-
universal_newlines=True
16+
universal_newlines=True,
17+
startupinfo=startupinfo
1218
).strip()
19+
1320
if "\\" in res:
14-
res = res.rsplit("\\", 1)[1]
21+
res = res = res.rsplit("\\", 1)[1]
22+
1523
return res
1624

1725

UI/translations/ru_RU.qm

-76 Bytes
Binary file not shown.

UI/translations/ru_RU.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ p, li { white-space: pre-wrap; }
3636
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';"> Follow the installer instructions. Installation is almost entirely automatic. <br /></span></p>
3737
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-weight:600; text-decoration: underline; color:#008f96;">Terms Of Use</span></p>
3838
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; color:#0000ff;"><br /></p>
39-
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';">1. This unlocker is distributed absolutely free of charge. Any commercial use of this unlocker is prohibited. If you purchased from any source, please refund and give a negative review.</span></p>
39+
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';">1. This unlocker is distributed absolutely free of charge. Any commercial use of this unlocker is prohibited.</span></p>
4040
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
4141
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';">2. THIS UNLOCKER IS PROVIDED "AS IS". NO WARRANTIES ARE PROVIDED OR IMPLIED. YOU USE THIS MODIFICATION OF THE ORIGINAL GAME AT YOUR OWN RISK. THE AUTHORS OF THE MODIFICATION WILL NOT BE LIABLE FOR ANY LOSSES OR DATA CORRUPTION, ANY LOST PROFITS IN THE PROCESS OF USE OR MISUSE OF THIS MODIFICATION.</span></p>
4242
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>
@@ -56,7 +56,7 @@ p, li { white-space: pre-wrap; }
5656
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; font-weight:600; text-decoration: underline;"><br /></p>
5757
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-weight:600; text-decoration: underline;">Установка</span><span style=" font-family:'MS Shell Dlg 2';">:</span></p>
5858
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';"> Следуйте инструкциям инсталлятора. Установка почти полностью автоматическая. <br /></span></p>
59-
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-weight:600; text-decoration: underline; color:#008f96;">Terms Of Use</span></p>
59+
<p align="center" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2'; font-weight:600; text-decoration: underline; color:#008f96;">Правила использования</span></p>
6060
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'MS Shell Dlg 2'; color:#0000ff;"><br /></p>
6161
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'MS Shell Dlg 2';">1. Данный разблокировщик распространяется абсолютно бесплатно. Любое коммерческое использование данного разблокировщика запрещается.Если вы разблокировщик в каком-либо магазине, пожалуйста, верните деньги и оставьте отрицательный отзыв.</span></p>
6262
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p>

UI/translations/zh_CN.qm

-76 Bytes
Binary file not shown.

UI/translations/zh_CN.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<translation>欢迎</translation>
2323
</message>
2424
<message>
25-
<location filename="ui_main.ui" line="1207"/>
25+
<location filename="../ui_main.ui" line="1207"/>
2626
<source>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
2727
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
2828
p, li { white-space: pre-wrap; }
@@ -36,7 +36,7 @@ p, li { white-space: pre-wrap; }
3636
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;MS Shell Dlg 2&apos;;&quot;&gt; Follow the installer instructions. Installation is almost entirely automatic. &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
3737
&lt;p align=&quot;center&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;MS Shell Dlg 2&apos;; font-weight:600; text-decoration: underline; color:#008f96;&quot;&gt;Terms Of Use&lt;/span&gt;&lt;/p&gt;
3838
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:&apos;MS Shell Dlg 2&apos;; color:#0000ff;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
39-
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;MS Shell Dlg 2&apos;;&quot;&gt;1. This unlocker is distributed absolutely free of charge. Any commercial use of this unlocker is prohibited. If you purchased from any source, please refund and give a negative review.&lt;/span&gt;&lt;/p&gt;
39+
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;MS Shell Dlg 2&apos;;&quot;&gt;1. This unlocker is distributed absolutely free of charge. Any commercial use of this unlocker is prohibited.&lt;/span&gt;&lt;/p&gt;
4040
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;
4141
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:&apos;MS Shell Dlg 2&apos;;&quot;&gt;2. THIS UNLOCKER IS PROVIDED &amp;quot;AS IS&amp;quot;. NO WARRANTIES ARE PROVIDED OR IMPLIED. YOU USE THIS MODIFICATION OF THE ORIGINAL GAME AT YOUR OWN RISK. THE AUTHORS OF THE MODIFICATION WILL NOT BE LIABLE FOR ANY LOSSES OR DATA CORRUPTION, ANY LOST PROFITS IN THE PROCESS OF USE OR MISUSE OF THIS MODIFICATION.&lt;/span&gt;&lt;/p&gt;
4242
&lt;p style=&quot;-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;br /&gt;&lt;/p&gt;

UI/ui_dialog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def setupUi(self, Dialog):
8989
self.gridLayout.setVerticalSpacing(0)
9090
self.gridLayout.setObjectName("gridLayout")
9191
self.bn_east = QtWidgets.QPushButton(self.frame_bottom)
92-
self.bn_east.setMinimumSize(QtCore.QSize(69, 25))
93-
self.bn_east.setMaximumSize(QtCore.QSize(69, 25))
92+
self.bn_east.setMinimumSize(QtCore.QSize(80, 25))
93+
self.bn_east.setMaximumSize(QtCore.QSize(80, 25))
9494
font = QtGui.QFont()
9595
font.setFamily("Segoe UI")
9696
font.setPointSize(12)

UI_logic/MainWindow.py

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from PyQt5.QtCore import Qt, QUrl, QTimer, QTranslator
1111
from subprocess import run, CREATE_NO_WINDOW
1212
from pathlib import Path
13+
from locale import getlocale
1314

1415
import UI.ui_main as ui_main
1516
from Libs.ConnectionCheck import ConnectionCheckThread
@@ -37,12 +38,12 @@ def __init__(self):
3738
self.game_path = None
3839
self.not_updated_dlc = []
3940
self.dlc_data = get_dlc_data()
41+
self.user_logon_name = get_user_logon_name()
4042
self.server_url, self.server_alturl = (lambda d: (d['url'], d['alturl']))(get_server_data())
4143
self.path_change()
4244
self.kill_process('Paradox Launcher.exe')
4345
self.kill_process('stellaris.exe')
4446

45-
4647
self.draggable_elements = [self.frame_user, self.server_status, self.gh_status, self.lappname_title,
4748
self.frame_top]
4849
for element in self.draggable_elements:
@@ -82,6 +83,7 @@ def __init__(self):
8283
self.en_lang.toggled.connect(self.switch_to_english)
8384
self.ru_lang.toggled.connect(self.switch_to_russian)
8485
self.cn_lang.toggled.connect(self.switch_to_chinese)
86+
8587
self.connection_thread = ConnectionCheckThread(self.server_url)
8688

8789
self.connection_thread.github_status_checked.connect(self.handle_github_status)
@@ -112,8 +114,45 @@ def __init__(self):
112114
self.log_widget = self.log_widget
113115
self.log_widget.clear()
114116

117+
def get_app_language(self):
118+
lang, _ = getlocale()
119+
if not lang:
120+
return "en"
121+
lang = lang.lower()
122+
if "russian" in lang:
123+
return "ru"
124+
elif "chinese" in lang:
125+
return "zh"
126+
else:
127+
return "en"
128+
129+
130+
def set_language_radio(self, lang):
131+
if lang == "ru":
132+
self.ru_lang.setChecked(True)
133+
elif lang == "zh":
134+
self.cn_lang.setChecked(True)
135+
else:
136+
self.en_lang.setChecked(True)
137+
138+
self.apply_language(lang)
139+
140+
def apply_language(self, lang):
141+
app = QApplication.instance()
142+
app.removeTranslator(self.translator)
143+
144+
if lang == "ru":
145+
if self.translator.load(os.path.join("UI", "translations", "ru_RU.qm")):
146+
app.installTranslator(self.translator)
147+
elif lang == "zh":
148+
if self.translator.load(os.path.join("UI", "translations", "zh_CN.qm")):
149+
app.installTranslator(self.translator)
150+
151+
self.retranslateUi(self)
152+
115153
def showEvent(self, event):
116154
super(MainWindow, self).showEvent(event)
155+
self.set_language_radio(self.get_app_language())
117156
print('Start connection check')
118157
QTimer.singleShot(5, self.start_connection_check)
119158
print('Start updates check')
@@ -280,7 +319,6 @@ def handle_github_status(self, status):
280319
self.errorexec(self.tr("Can't establish connection with GitHub. Check internet"), self.tr("Ok"),
281320
exitApp=True)
282321

283-
284322
def handle_server_status(self, status):
285323
if status:
286324
self.server_status.setChecked(True)
@@ -330,11 +368,10 @@ def checkDLCUpdate(self):
330368
md5_checker = MD5(f"{self.game_path}\\dlc", self.server_url)
331369
return md5_checker.check_files()
332370

333-
@staticmethod
334-
def full_reinstall():
371+
def full_reinstall(self):
335372
try:
336373
print(f'Deleting documents folder...')
337-
user_home = os.path.join("C:\\Users", get_user_logon_name())
374+
user_home = os.path.join("C:\\Users", self.user_logon_name)
338375
rmtree(os.path.join(user_home, "Documents", "Paradox Interactive", "Stellaris"))
339376
except Exception as e:
340377
print(f'Cant delete {e}')
@@ -417,7 +454,11 @@ def unlock(self):
417454
if not os.path.exists(os.path.join(self.game_path, "dlc")):
418455
os.makedirs(os.path.join(self.game_path, "dlc"))
419456
if self.game_path:
420-
self.remove_compatibility(f"{self.game_path}\stellaris.exe")
457+
try:
458+
self.remove_compatibility(f"{self.game_path}\stellaris.exe")
459+
except Exception as e:
460+
print(f"Cant remove compatibility: {e}")
461+
pass
421462
self.is_downloading = True
422463
if self.update_dlc_button.isChecked():
423464
print("Updating DLCs...")
@@ -551,7 +592,7 @@ def reinstall(self):
551592
if not self.skip_launcher_reinstall_checbox.isChecked():
552593
self.reinstall_thread = ReinstallThread(self.game_path, paradox_folder1, paradox_folder2, paradox_folder3,
553594
paradox_folder4, self.launcher_downloaded,
554-
self.downloaded_launcher_dir, get_user_logon_name())
595+
self.downloaded_launcher_dir, self.user_logon_name)
555596
# self.reinstall_thread.progress_signal.connect(self.update_reinstall_progress)
556597
self.reinstall_thread.error_signal.connect(self.show_reinstall_error)
557598
self.reinstall_thread.continue_reinstall.connect(self.reinstall_2)
@@ -618,6 +659,8 @@ def replace_files(self, launcher_folder):
618659
print('Copy complete')
619660
self.copy_files_radio.setChecked(True)
620661
self.lauch_game_checkbox.setVisible(True)
662+
self.update_dlc_button.setVisible(False)
663+
self.old_dlc_text.setVisible(False)
621664
self.done_button.setVisible(True)
622665
print('All done!')
623666

0 commit comments

Comments
 (0)